TVirtualDrawtree

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

mrmarman , i will explain what my code doing i cant get too many equations together i have to done from 1 big problem then i can have equations from first example code , if i do every thing wrong and no correction i will be like a baby who do mistake in my whole life until some one tell me that iam doing mistake and show me the correct way to do ,


my code logic and for current iam talking only about grabbing lists of client for each channel

what i think about my code in old days i loop through the all connections to grab there current channel id and then send the list to each connection who have the similar channel id

Kod: Tümünü seç

   for Index_Room := 0 to Connections.Count -1 do
   begin
      Break;
    end;
    for I := 0 to Connections.Count - 1 do
    begin
      Connection := TConnection(Connections.Items[I]);
      if {(Connection.UniqueID <> UniqueID) and} (Connection.Channel = TConnection(Connections[Index_Room]).Channel) then
      SL.Add(Connection.Name + Sep + IntToStr(Connection.UniqueID) + Sep);
    end;
and then i combine what i did before with your send list fixed code

Kod: Tümünü seç

    for I := 0 to Connections.Count - 1 do
    begin
      Connection := TConnection(Connections.Items[I]);
      if (SL.Count > 0)  then
      begin
        MS := TMemoryStream.Create;
        try
          SL.SaveToStream(MS);
          MS.Position := 0;
          SendCommandAndStream(Connection, 'GETLIST', MS);
          // SendStream(TheConnection, Ms);
        finally
          MS.Free;
        end;
      end;
    end;
  finally
    SL.Free;
  end;
end;
if you try to run my example in the project you will find a pitfalls , try to run my client with 3 cients first you successfully grab clients for each channel but try to move to another channel as example move from channel 1 to channel 2 and see what happend , your name will be shown to other clients and there names will disappear i think its something with Getlist command , here is example photo

and before i show example photo here is my handler on client side for channel change

Kod: Tümünü seç

if Command = 'Channel' then
  begin
    mMessage.Lines.Add(Params[1] + ' Change to  Channel : ' + Params[2]);
    SendCommand(TCPClient, 'GETLIST');

  end;
Resim
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

The writing code is easy, the logic is hard. I need to know the workflow.

(Q1) if a client changes its channel from (1) to the (2) or back, what does happen ? channel (1) will be Offline or both two channel gets online state.
(Q2) Every channel changing event must refresh the GETLIST event. Doesn't it ?
(Q3) All the clients channel state changing do broadcast again and again. Then if the server knows all the users on which channel, server may get this broadcasting work on itself. No need to broadcast again to the all clients, Doesn't it ?

I cannot see this answers in your code.
That is one thing I can say; The GETLIST message must be have a channel parameter to know clients that which channel asking and do feedback if the client on same channel.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

if the client changed to channel 2 his name must be disappear from channel 1 to other clients thats why i send the list again , but the bug its disppear the other clients names and show the one who change the channel did you got me now
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

should i do check

Kod: Tümünü seç

if Channelid <> IntToStr(channel) then
i really cannot get it works , its been 2 days now can i have little help with it :(

let me make the logic more clear

if user in channel 1 change channel to

Kod: Tümünü seç

channel 2
Load user in channel 2 to him and show the users in channel 1 to other connected clients its kinda acknowledge of who is currently in this channel like chat room as paltalk etc..
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

i strongly need little help with this part too many issues i have :(
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

Server Side
// Added one more parameter for Channel information without any !client! or !channel! restriction!
The client who get this information will know that which user(s) at the same channel by itself.

Kod: Tümünü seç

    for I := 0 to Connections.Count - 1 do
    begin
      Connection := TConnection(Connections.Items[I]); 
      SL.Add(Connection.Name + Sep + IntToStr(Connection.UniqueID) + Sep + IntToStr(Connection.Channel) + Sep); // !!!
    end;

    // Send List
    for I := 0 to Connections.Count - 1 do
    begin
      Connection := TConnection(Connections.Items[I]);
      if (SL.Count > 0)  then
      begin
        MS := TMemoryStream.Create;
        try
          SL.SaveToStream(MS);
          MS.Position := 0;
          SendCommandAndStream(Connection, 'GETLIST', MS);
        finally
          MS.Free;
        end;
      end;
    end;
Client Side
// ExplodeLine procedure rebuilded for Channel information parse operation. strChannel parameter added, you see...

Kod: Tümünü seç

procedure ExplodeLine(Line: string; var strName, strUniqueID, strChannel: string);
var
  P, I: Integer;
begin
  I := 0;
  repeat
    P := Pos(Sep, Line);
    if P <> 0 then
    begin
      Inc(I);
      case I of
        1: strName     := Copy(Line, 1, P - 1);
        2: strUniqueID := Copy(Line, 1, P - 1);
        3: strChannel  := Copy(Line, 1, P - 1);
      end;
      Delete(Line, 1, P + Length(Sep) - 1);
    end;
  until (I = 3) or (P = 0) or (Line = '')
end;
// Client project can filter itself like before. So that according the channel information.

Kod: Tümünü seç

  if Command = 'GETLIST' then
  begin
    if ListView1.Selected <> nil
      then strSelectedUID := Listview1.Selected.SubItems[3]
      else strSelectedUID := '';
    Memo1.Lines.Add('GETLIST');
    ListView1.Items.Clear;
    if Assigned(MS) then
    begin
      SL := TStringList.Create;
      try
        SL.LoadFromStream(MS);
        for I := 0 to SL.Count -1  do
        begin
            Line := SL.Strings[I];
            ExplodeLine(Line, strName, strUniqueID, strChannel);
            boolblink := not boolblink;
            filename := '';
            if strChannel =  IntToStr(Channel) then // This is the trick shot for channel filtering... Only active channel users will be added
              Add_Item( strName, ListView1, FileName, boolblink, strUniqueID, Status);
        end;
      finally
        SL.Free;
      end;
      MS.Free;
      SendCommandWithParams( TCPClient, 'STATUSCHANGE', IntToStr(UniqueID) + Sep + Status + Sep);
      if strSelectedUID <> '' then
      begin
        for i := 0 to ListView1.Items.Count-1
          do if ListView1.Items[i].SubItems[3] = strSelectedUID
            then Listview1.Items[i].Selected := True;
      end;
    end;
  end;
I don't send any source attached this message, because you must place the code above by yourself to figure out that why do we do this.

This for education purposes.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

omgggggggggg , its finally workinggggggggggggggg ,,,, i spend 3 days to know how to do if statment to the channel if for getlist thats why i have to see some code from begining :(((( thank you mr marman is it workiiiiingggggggggggggggggggggggg finallyyyyyyyyyyyyyyyyyyyyy
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

mrmarman yazdı: That is one thing I can say; The GETLIST message must be have a channel parameter to know clients that which channel asking and do feedback if the client on same channel.
You're welcome.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

inanılmaz abiiiiiiiiiiiiii
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

mrmarman , i have problem with downloading images using winnet ,

first problem its freezing the application too much if image size are huge

also list view shows blank until images downloaded , can i add item text first then adding there images ?

here is the downloader code

Kod: Tümünü seç

procedure DownloadToStream(const Url: string; ms: TMemoryStream);
var
  hSession     : HINTERNET;
  hService     : HINTERNET;
  lpBuffer     : array[0..1023] of Byte;
  dwBytesRead  : DWORD;
  dwBytesAvail : DWORD;
  dwTimeOut    : DWORD;
begin
  hSession := InternetOpen('sessionname', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  if not Assigned(hSession) then Exit;
  try
    hService := InternetOpenUrl(hSession, PChar(Url), nil, 0, 0, 0);
    if hService = nil then
      Exit;
    try
      dwTimeOut := 60000;
      InternetSetOption(hService, INTERNET_OPTION_RECEIVE_TIMEOUT, @dwTimeOut, SizeOf(dwTimeOut));
      if InternetQueryDataAvailable(hService, dwBytesAvail, 0, 0) then
      repeat
      Application.ProcessMessages;
        if not InternetReadFile(hService, @lpBuffer[0], SizeOf(lpBuffer), dwBytesRead) then
          Break;
        if dwBytesRead <> 0 then
          ms.WriteBuffer(lpBuffer[0], dwBytesRead);
      until dwBytesRead = 0;
    finally
      InternetCloseHandle(hService);
    end;
  finally
    InternetCloseHandle(hSession);
  end;
end;
here is adding items

Kod: Tümünü seç

Procedure TChatFo.Add_Item( strCaption: String; ListView : TListView; strFile: String; boolBlink : Boolean; strUniqueID:String; Currentstatus: string);
Var
  MS : TMemoryStream;
  ResStream : TResourceStream;
begin
Currentstatus := Status;
  if Strfile = '' then
begin
  aGIF := TGifImage.Create;
  ResStream  := TResourceStream.Create(HInstance, 'f1', RT_RCDATA);
  aGIF.LoadFromStream( ResStream );
  ResStream.Free;
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption );                   // subitem 0
    SubItems.AddObject( 'IMA', TObject( aGif ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' )               // subitem 2
      else  SubItems.Add( '' );                   // subitem 2
    SubItems.Add( strUniqueID );                  // subitem 3 // UniqueID
    SubItems.Add('-');                            // subitem 4 // Next User Idx (beside)
    SubItems.Add(Currentstatus);                            // subitem 5 // StateIdx
  end;
end else

begin
  MS := TMemoryStream.Create;
  DownloadToStream(strFile, ms);// start downloading file to stream
  ms.Position := 0;
  if ExtractFileExt(strFile) = '.gif' then  // if image is gif
begin
  aGIF := TGifImage.Create;
  aGIF.LoadFromStream(MS);
  aGIF.Transparent := True;
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    SubItems.AddObject( 'IMA', TObject( aGif ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
      SubItems.Add( strUniqueID );                  // subitem 3 // UniqueID
    SubItems.Add('-');                            // subitem 4 // Next User Idx (beside)
    SubItems.Add(Currentstatus);                              // subitem 5 // StateIdx
  end;
end;


if ExtractFileExt(strFile) = '.jpg' then // if image jpg
begin
  jpg := TJPEGImage.Create;
  jpg.LoadFromStream(MS);
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    SubItems.AddObject( 'IMA', TObject( jpg ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
       SubItems.Add( strUniqueID );                  // subitem 3 // UniqueID
    SubItems.Add('-');                            // subitem 4 // Next User Idx (beside)
    SubItems.Add(Currentstatus);                            // subitem 5 // StateIdx
  end;
end;

if ExtractFileExt(strFile) = '.png' then //if image png
begin
  png := TPngImage.Create;
  png.LoadFromStream(MS);
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    SubItems.AddObject( 'IMA', TObject( png ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
      SubItems.Add( strUniqueID );                  // subitem 3 // UniqueID
    SubItems.Add('-');                            // subitem 4 // Next User Idx (beside)
    SubItems.Add(Currentstatus);                             // subitem 5 // StateIdx
  end;
end;

  // DO NOT Free this image because now it is a SubItems[1] Object
  FreeAndNil(MS);
end;
end;
important point how do i avoid freezing application when downloading ?
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

Use this for downloading. You allready have the IdAntiFreeze on the form I saw before. It prevents freeze.

Kod: Tümünü seç

Uses IdHttp;

procedure DownloadToStream(const Url: string; ms: TMemoryStream);
Var
  aIdHttp : TIdHttp;
begin
  aIdHttp := TIdHttp.Create(nil);
  Try
    aIdHttp.Get( Url, MS );
    MS.Seek(0, soFromBeginning);
  Finally
    aIdHttp.Free;
  End;
end;
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

idhttp its freezes also some how and slow and too much heavy thats why i moved to winnet , i know that antifreeze doesn't freeze the threads but its kinda laggy with idhttp
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

Then you create your own and go over that thread. Internet access always slow down project without threading.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

ok what about items , its shows blank until the image downloaded , how may i show the username in listview first then download his image
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

You draw a text over a default image on it.

Canvas.TextOut you know.
Resim
Resim ....Resim
Cevapla