开发者

Delphi : dynamically Create TClientSocket

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜