Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 339
opc0de Avatar asked Mar 24 '26 07:03

opc0de


2 Answers

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,

like image 154
RBA Avatar answered Mar 26 '26 02:03

RBA


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

Solved it!

like image 25
opc0de Avatar answered Mar 26 '26 01:03

opc0de



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!