BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Events

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket)
View previous topic :: View next topic  
Author Message
bigtommy
Guest





PostPosted: Thu Apr 28, 2005 8:26 am    Post subject: Events Reply with 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


Back to top
Hans Galema
Guest





PostPosted: Thu Apr 28, 2005 9:00 am    Post subject: Re: Events Reply with quote



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





PostPosted: Thu Apr 28, 2005 9:03 am    Post subject: Re: Events Reply with quote



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





PostPosted: Thu Apr 28, 2005 9:14 am    Post subject: Re: Events Reply with quote

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 Smile
Tomek



Back to top
bigtommy
Guest





PostPosted: Thu Apr 28, 2005 9:16 am    Post subject: Re: Events Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.