Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 09-27-2002, 03:50 PM
Ouiji Ouiji is offline
Senior Member
 
Join Date: Nov 2001
Location: US of A
Posts: 478
Send a message via AIM to Ouiji
Default Reading From TClientSockets That Are Created With A Variable

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
Reply With Quote
  #2  
Old 09-28-2002, 09:23 AM
Andreaz Andreaz is offline
Senior Member
 
Join Date: Jun 2002
Posts: 116
Default RE: Reading From TClientSockets That Are Created With A Variable

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
If it helped please Accept...
Reply With Quote
  #3  
Old 09-28-2002, 09:52 AM
Ouiji Ouiji is offline
Senior Member
 
Join Date: Nov 2001
Location: US of A
Posts: 478
Send a message via AIM to Ouiji
Default RE: Reading From TClientSockets That Are Created With A Variable

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
Reply With Quote
  #4  
Old 09-28-2002, 01:47 PM
Andreaz Andreaz is offline
Senior Member
 
Join Date: Jun 2002
Posts: 116
Default RE: Reading From TClientSockets That Are Created With A Variable

Did you assign the event properly:

Socket[i].onConnect:= Form1.ClientSocketConnect;

/Andreas
If it helped please Accept...
Reply With Quote
  #5  
Old 05-13-2005, 03:39 AM
y2kbug y2kbug is offline
Junior Member
 
Join Date: May 2005
Posts: 1
Default RE: Reading From TClientSockets That Are Created With A Variable

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 09:45 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.