![]() |
|
#1
|
|||
|
|||
|
I am attempting to get TSocketNotifyEvent in a procedure from TClientSockets created like this:
Global Var socket: Array [1..100] of TClientSocket; Created with: socket[i] := TClientSocket.Create(nil); Is this possable? -ouiji ouiji@ouiji.net |
|
#2
|
|||
|
|||
|
Yepp, It's possible: (and not all to hard)
procedure TMainForm.ClientSocketConnect(Sender: TObject; Socket: TCustomWinSocket); begin //Check witch of the components that called the fuction, if needed: IF Sender = Socket[i] then begin //Do what should be done end; //or just send a mess: Socket.WriteStr('Hello'); end; ... Socket[i]:= TClientSocket.Create(nil); Socket[i].onConnect = Form1.ClientSocketConnect; Hope it helps.. /Andreas |
|
#3
|
|||
|
|||
|
I was playing around with that type of proceedure, but I can never get it to trigger...
procedure TForm1.ClientSocketConnect(Sender: TObject; Socket: TCustomWinSocket); var ii:integer; begin ShowMessage('Connection...'); for ii := 1 to cnum do begin IF Sender = ircsocket[ii] then begin ShowMessage('Connected'); end; end; end; If there is a socket defined.. as in VCL component clientsocket, will it interfere? -ouiji |
|
#4
|
|||
|
|||
|
Did you assign the event properly:
Socket[i].onConnect:= Form1.ClientSocketConnect; /Andreas |
|
#5
|
|||
|
|||
|
Well I has the same problem, you can't assing this event like this:
Socket[i].onConnect:= Form1.ClientSocketConnect; I programm in c++ builder, so the solution is use a "Dummy Class", the event needs to be in a class like this: class TDummy { public: void __fastcall ClientSocketConnect(System::TObject* Sender, TCustomWinSocket* Socket) { try { Socket->SendBuf((void *) Respuesta, sizeof(TRespuesta)); } catch(...){} } void __fastcall ClientSocketError(System::TObject* Sender, TCustomWinSocket* Socket, Scktcomp::TErrorEvent ErrorEvent, int &ErrorCode) { ErrorCode = 0; } TDummy(){} }; ------------------- TDummy *DummyClass = new TDummy(); Respuesta = new TRespuesta; TClientSocket *ClientSocket = new TClientSocket(NULL); if (ClientSocket) { ClientSocket->OnConnect = DummyClass->ClientSocketConnect; ClientSocket->OnError = DummyClass->ClientSocketError; } ... Excuse my bad english, I hope can help you this ----------------------------------- Divide y vencerás |
![]() |
| Thread Tools | |
| Display Modes | |
|
|