Hello Jack,

You need a hidden window in hour object where you can post messages to.
This is some copy/past what I'm just doing :)

// inconstructor you create a window and give the wndProc functio addr
// (see below)
constructor TVehicle.Create(const FileName: string);
begin
   inherited;
   FHandle := AllocateHWND(WndProc);
end;

// destroy the window in destrocusr
destructor TVehicle.Destroy;
begin
   Cli.Free;
   DeAllocateHWND(FHandle);
   inherited;
end;

// this is the proc that ge the messages.
// dont forget to call the DefWndowProc witch returns the default values
// for various messages
procedure TVehicle.WndProc(var MsgRec: TMessage);
begin
   with MsgRec do
      case Msg of
         WM_CONNECT: WMConnect(MsgRec);
      else
         Result := DefWindowProc(FHandle, Msg, wParam, lParam);
      end;
end;

And the WMConnect in this example is declared just as it was in a form,
however there is little difference:

I declare it normally as this:

procedure WMConnect(var Msg: TMessage); message WM_CONNECT;

So it has to be if you do in eg a form. However since you control the
WndProc yourself the 'message WM_CONNECT' is not nececary. However I
like to have most of my units written same way, so I do it like this.

---
Rgds, Wilfried
http://www.mestdagh.biz

Thursday, May 19, 2005, 00:50, Jack wrote:

> Hello Francois,

> I'm not using a TDataModule but as I mentioned in my other email,
> I created an object to own the array of TWSocket objects.

> Now I have a new question that relates to the dependency of the
> main form. I'm reusing the sockets. So when a socket is
> disconnected, I assign a different IP and connect again. I understand
> that I can not do this in the OnSessionClosed event handler (or
> that didn't work.) Instead, I need to post a message to the main
> form, and reconnect in the windows message handler. This also
> introduces a dependency to the main form, and adds and some code
> in the main form unit. Is there any other way to defer the call to
> the Connect function so that it will happen after the code exits
> the OnSessionClosed event handler? I know I can create a hidden
> window in the owner object but I would avoid doing that if there
> is an easier way.

> -- 
> Best regards,
> Jack

>>> The reason I was thinking of a multi-threaded client is that
>>> I want to isolate this module with the main form.

FP>> No need to have multithread for that. Just put your TWSocket into a
FP>> TDataModule. It's enough.
FP>> You can evn create them dynamicall in a pure .pas unit.

FP>> fyi: Message handlers can be put everywhere, it doesn't matter.


FP>> ----- Original Message ----- 
>>> Hello Francois and all,
>>>
>>> I saw a thread server sample in ICS package but did not
>>> see any sample for threaded client. I understand that with
>>> ICS I don't have to do multi-threading. The reason I was
>>> thinking of a multi-threaded client is that I want to isolate
>>> this module with the main form. The module is supposed to
>>> create multiple sockets to test a group of servers. I suppose
>>> this can be achieved with an array of wsocket objects in a
>>> single-threaded application but the socket will have to have
>>> something to do with the main form? For example, parent-ed by
>>> the main form, or the message handlers defined in the main form.
>>> (I could be wrong.) That's why I'm thinking of using a separate
>>> group of threads to do the server check. I wonder if there are
>>> samples for the client.
>>>
>>> -- 
>>> Best regards,
>>> Jack




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