Delphi: dynamically create a TClientSocket

I am trying to create a TClientsocket at runtime, but I cannot assign events.

I use

var
  cs:TCLIENTSOCKET;

procedure OnReadx;
begin

end;

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

This does not work. What is the right way to do this?

+3
source share
2 answers

and the event is declared as follows

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

so that you write a function with these parameters, for example

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

and assign it as in the code:

cs.OnRead:=OnReadx;

Regards,

+4
source

The problem is that the TClientSocket class requires the event handlers for its various events to be method pointers (they must belong to some object), unlike ordinary procedures.

I decided!

+3
source

Source: https://habr.com/ru/post/1770278/


All Articles