problem with rearrange items in list view

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

problem with rearrange items in list view

Mesaj gönderen mia »

hello ramadan mubarak , i have problem when iam trying to rearrange items in list view where there sub item equal specif string , i been following mrmarman direction and i thank him for teaching me a lot of things and mystery . here is my current code for rearrange items

rearrange function

Kod: Tümünü seç

procedure ExchangeItems(lv: TListView; i, j: Integer);
var
  tempLI: TListItem;
begin
  lv.Items.BeginUpdate;
  try
    tempLI := TListItem.Create(lv.Items);
    tempLI.Assign(lv.Items.Item[i]);
    lv.Items.Item[i].Assign(lv.Items.Item[j]);
    lv.Items.Item[j].Assign(tempLI);
    tempLI.Free;
  finally
    lv.Items.EndUpdate
  end;
end;

Kod: Tümünü seç


var
R:integer;
  if Command = 'stream' then
begin
     strUniqueID := Params[1];
      for i := 0 to ListView1.Items.Count-1
    do if ListView1.Items[i].SubItems[3] = Trim(strUniqueID) then
  begin
   R:= listview1.Items[i].Index;
   ExchangeItems( ListView1, R, 0);
  end; 
  end;
  
in my client and server i send command called stream to update the visual items in listview to show to other clients who is streaming right now . but some times its showing other names that they are not streaming what i did wrong with the code ?
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
freeman35
Admin
Mesajlar: 2381
Kayıt: 12 Haz 2003 04:05
Konum: merkez camii yanı

Re: problem with rearrange items in list view

Mesaj gönderen freeman35 »

Amin, ecmain.
can you test this?
//do if ListView1.Items.SubItems[3] = Trim(strUniqueID) then
do if Trim( ListView1.Items.SubItems[3] ) = Trim(strUniqueID) then

and/or this line too,
do if uppercase( Trim( ListView1.Items.SubItems[3] ) )= UpperCase( Trim(strUniqueID) )then
ZAGOR TENAY TÜRK'tür... TÜRK kalacak...
Zoru başarırım, İmkansız zaman alır
FreeMan 35.5

Soru sormaya üşenmiyorsan, sorunun çözümünü yazmaya da üşenme !!!
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: problem with rearrange items in list view

Mesaj gönderen mia »

i tried adding trim still some times other connected names shows as streamers

Kod: Tümünü seç

if Command = 'stream' then
 begin
     strUniqueID := Params[1];
      for i := 0 to ListView1.Items.Count-1
    do if Trim(ListView1.Items[i].SubItems[3]) = Trim(strUniqueID) then
  begin
   R:= listview1.Items[i].Index;
   ExchangeItems( ListView1, R, 0);
  end;
   end;
and here is the update listview code when some one start stream check if recorder.Active block

Kod: Tümünü seç

if Command = 'GETLIST' then
  begin
    if ListView1.Selected <> nil
      then strSelectedUID := Listview1.Selected.SubItems[3]
      else strSelectedUID := '';
    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];
            usergetlist(Line, strName, strUniqueID, strChannel, icon);
           Add_Item( strName, ListView1, icon, boolblink, strUniqueID, Status);
        end;
      finally
        SL.Free;
      end;
      MS.Free;
      if recorder.Active = True then// if the client recording send the stream command to show him on top
      begin
      SendCommandWithParams(TCPClient, 'stream', IntToStr(UniqueID) + Sep);
      end;
    end;
  end;
uniqueid in this case is = strUniqueID := Params[1]; in stream handler
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
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: problem with rearrange items in list view

Mesaj gönderen mrmarman »

Hi mia...

I'm trying to understand. Which project must inform you that who is streaming to whom.
The server always must know what is going on the network.
So that, you can ask this the only the server.

If a user starts the stream, then the server indicates it by a check value on the listview, isn't it ?
Now you describe us with code sample please that the server side and client side happenings.

So, after all of that; the Client Listview rearrange operation will use the server listings.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: problem with rearrange items in list view

Mesaj gönderen mia »

iam going to upload the complete code as exe to get better understand results
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
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: problem with rearrange items in list view

Mesaj gönderen mia »

i created the client and server as exe with stream command handler work flow codes

client side


main unit mainunit

added global boolean variable called istreaming to check if client streaming then send streaming command when GETLIST command called

Kod: Tümünü seç

  if istreaming = true then
      begin
        SendCommandWithParams( TCPClient, 'Startstream', IntToStr(UniqueID) + Sep);
      end;
start stream command handle

Kod: Tümünü seç

  if command = 'Startstream' then
   begin
     strUniqueID := Params[1];
      for i := 0 to ListView1.Items.Count-1
    do if ListView1.Items[i].SubItems[3] = Trim(strUniqueID) then
  begin
   R:= listview1.Items[i].Index;
  end;
   Panel2.Top  := xSelItemTop;
   panel2.Visible := true;
   ExchangeItems( ListView1, R, 0);
   end;

end;

server side included start stream command handler and change channel handler , problem is some times when client change the channel and go back to the first channel the other client who streaming name not showing as first name with panel gray line other names are coming to first index
Dosya ekleri
client stream.rar
(87.95 KiB) 37 kere indirildi
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Cevapla