Search code examples
delphidelphi-7

Delphi : dynamically Create TClientSocket


I am trying to create a TClientsocket at runtime but I can't assign the events.

I use

var
  cs:TCLIENTSOCKET;

procedure OnReadx;
begin

end;

procedure intsok;
begin
  cs:=Tclientsocket.create(nil);
  cs.OnRead:=OnReadx;
end;

It doesn't work. what is the right way to do this?


Solution

  • and the event is declared like this

    TSocketNotifyEvent = procedure (Sender: TObject; Socket: TCustomWinSocket) of object;
    

    so you've wrote a function with those parameters, e.g

    procedure OnReadx(Sender: TObject; Socket: TCustomWinSocket);
    

    and assign it like in your code:

    cs.OnRead:=OnReadx;
    

    best regards,