开发者

Delphi : dynamically Create TClientSocket

开发者 https://www.devze.com 2023-01-20 22:38 出处:网络
I a开发者_StackOverflowm trying to create a TClientsocket at runtime but I can\'t assign the events.

I a开发者_StackOverflowm 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?


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,


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号