Here is an example setting up a messagepump in a thread in C++, the aproach
is the same with delphi:

void __fastcall MyIOThread::Execute()
{
   MSG msg;
   bool FinishThread=false;
   while(!Terminated && !FinishThread && GetMessage(&msg, 0, 0, 0))
   {
      try
      {
            switch(msg.message)
            {
               case WM_MY_CUSTOM_FINISH:
                 FinishThread=true;
                 break;
               default:
                 TranslateMessage(&msg);
                 DispatchMessage(&msg);
                 break;
            }
      }
      catch(Exception &e)
      {
          MyCustomExceptionhandler(e);
      }
}

Just create your components and set the events before the while, then you
can do what you want. TWSocket, TTimer ect, all events will trigger. And if
you from outside the thread want to finish the thread, you just post a
message to the thread with the message WM_MY_CUSTOM_FINISH (you must define
this your self, WM_USER + some value not already used).

Create as many components as you want. This setup will handle all the
windows messages within this thread and there is no need to call
Application->ProcessMessages or anything. TranslateMessage and
DispatchMessage will make sure all components in this thread receive
messages and therefor can trigger the events.

Remember to destroy the components inside Execute.

Regards Bjørnar

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of [EMAIL PROTECTED]
Sent: 3. mai 2005 16:26
To: twsocket@elists.org
Subject: AW: [twsocket] ProcessMessages


> 
> > - the sending TWSocket doen't need to be created in an
> thread because that
> > sends at once (nearly) without the need of windows messages
> 
> Wrong. Sending and receiving btoh use messages, even if in some cases 
> it seems to be direct.

So the sending part must be in another thread and call MessageLoop as well
until the OnDataSent terminates the thread? Or how can I do this?

Greetings

Markus
--
To unsubscribe or change your settings for TWSocket mailing list please goto
http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be



--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to