| View previous topic :: View next topic |
| Author |
Message |
bigtommy Guest
|
Posted: Thu Apr 28, 2005 8:26 am Post subject: Events |
|
|
Hello,
Once again I cannot manage work with dynamically created components. Hans
helped me with creating TServerSocket by
TServerSocket* ServerSocket = new TServerSocket(NULL);
but I don't know how to hadle events not directly from the Object Inspector.
Could you please help or include links to other sites with solution
Tomek
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Thu Apr 28, 2005 9:00 am Post subject: Re: Events |
|
|
bigtommy wrote:
| Quote: | but I don't know how to hadle events not directly from the Object Inspector.
|
Do you mean that you want to assign eventhandlers to your dynamic
created instance of TServerSocket ?
In general you can do it in following way. First look how an eventhandler
would look like. For instance for the OnClientConnect event. Use
the Object Inspector to find out. It will give you:
void __fastcall TForm1::ServerSocket1ClientConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
}
Now in the class where you construct the ServerSocket add a
memberfunction:
void __fastcall TMyClass::ServerSocket1ClientConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
}
For the rest it is -in TMyClass-:
TServerSocket *ServerSocket = new TServerSocket ( NULL );
ServerSocket->OnClientConnect = ServerSocket1ClientConnect;
// use ...
delete ServerSocket; // you will not forget this!?
Hans.
|
|
| Back to top |
|
 |
Rafal Z Guest
|
Posted: Thu Apr 28, 2005 9:03 am Post subject: Re: Events |
|
|
bigtommy napisał(a):
| Quote: | Hello,
Once again I cannot manage work with dynamically created components. Hans
helped me with creating TServerSocket by
TServerSocket* ServerSocket = new TServerSocket(NULL);
but I don't know how to hadle events not directly from the Object Inspector.
Could you please help or include links to other sites with solution
Tomek
|
You have to create a procedure of the type of the event you want to
implement. For example OnClick has an event of the type: TNotifyEvent
that means:
Type TNotifyEvent=procedure(Sender: TObject);
or
Type TClientConnect procedure(Sender: TObject; Socket:
TCustomWinSocket);
the last declares a procedural type for the OnClientConnect of
TServerSocket.
If you know the type of procedure needed for Event you can implement
such Event:
procedure TForm1.ServerSocket1ClientConnect(Sender: TObject; Socket:
TCustomWinSocket);
begin
//some code
end;
Now you can assign this procedure to the Eventproperty of TServersocket:
SeverSocket1.OnClientConnect=ServerSocket1ClientConnect;
This could you do in FormCreate event of the Form. After this line the
event will be called each time the event OnClientConnect fires
|
|
| Back to top |
|
 |
bigtommy Guest
|
Posted: Thu Apr 28, 2005 9:14 am Post subject: Re: Events |
|
|
Thanks a lot again
As you've shown, my problem was caused by the lack of 1 line - the one
below.
| Quote: | ServerSocket->OnClientConnect = ServerSocket1ClientConnect;
|
I have created the function but made no connection to the component.
Now it works as good as new
Tomek
|
|
| Back to top |
|
 |
bigtommy Guest
|
Posted: Thu Apr 28, 2005 9:16 am Post subject: Re: Events |
|
|
Many thanks for your help and your time. I hope that soon I will also be
able to help others. I'm still just a begginer.
Tomek
|
|
| Back to top |
|
 |
|