question about synchronize Tidtcpserver execute

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

question about synchronize Tidtcpserver execute

Mesaj gönderen mia »

i have server application that uses indy tcpserver iam just trying to understand synchronize inside server execute i do something like this

Read the comment in server execute

Kod: Tümünü seç

uses 
Idsync;

....................
....................

  TConnection = class(TObject)
  Private

    public
    Name: String;
    Connected: TDateTime;
    UniqueID: DWORD;
    Thread: Pointer;
    procedure AddToListView;
  end;


procedure TConnection.AddToListView;
var
  LName: string;
  LIP: string;
  LConnected: TDateTime;
  LUniqueID: Dword;
  Item: TListItem;
begin
  LName := Self.Name;
  LConnected := Self.Connected;
  LUniqueID := Self.UniqueID;
  begin
      if (fMain = nil) or (fMain.lwConnections = nil) then Exit;
      Item := fMain.lwConnections.Items.Add;
      try
        Item.Data := Self;
        Item.Caption := LName;
        Item.SubItems.Add(FormatDateTime('hh:mm:ss', LConnected));
        Item.SubItems.Add(IntToStr(LUniqueID));
      except
        Item.Delete;
        raise;
      end;
    end;
end;



procedure TfMain.TCPServerExecute(AContext: TIdContext);
var
  Connection: TConnection;
begin
  Connection := Pointer(AContext.Data);

  if Command = 'LOGIN' then
  begin
    if Password <> Params[1] then
      AContext.Connection.Socket.WriteLn('INVALIDPASSWORD')
    else
     
  end;
  if Command = 'TAKEMYINFO' then //login ok, add to listview
  begin
    Connection.Name := Params[1];
    Connections.Add(Connection);
     TIdNotify.NotifyMethod(Connection.AddToListView);// is this a right way to synchronize ?
  end;

end;
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
G.Arkas
Üye
Mesajlar: 829
Kayıt: 01 Eki 2007 07:16
Konum: İstanbul
İletişim:

Re: question about synchronize Tidtcpserver execute

Mesaj gönderen G.Arkas »

Hi;
Please try this

Kod: Tümünü seç

TIdSync.SynchronizeMethod(AddToListView)
or maybe you need to new Thread class and should be customize your notify method.
Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: question about synchronize Tidtcpserver execute

Mesaj gönderen mia »

here is my project after derive Tidnotify class is this correct method ?
Dosya ekleri
Server.rar
(58.89 KiB) 53 kere indirildi
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Cevapla