Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 May : Re: Can I call a procedure from OnExecute?
| Subject: | Re: Can I call a procedure from OnExecute? |
| Posted by: | "PeaShooter_OMO" (jacquesv..@homemail.co.za) |
| Date: | Fri, 12 May 2006 22:11:52 |
Thank you very much
"Martin James" <mjames_falcon@dial.pipex.com> wrote in message
news:44620fb2@newsgroups.borland.com...
>> Can I call a procedure directly from OnExecute
>
> Sure. 'ReadLn' is a procedure call, OK, it's a method, but it's a still a
> call).
>
> and will that procedure be
>> incorporated into
>> the thread that the client connection is in
>
> Call/return does not, in itself, change thread context. A
> procedure/function/method *called* from the OnExecute event will be
> executed
> in the context of the caller, ie. the peer thread that called OnExecute.
> That procedure can call another, and that call another - it does not
> matter - the thread context will not change.
>
> or must it be in a Synchronize()
>
> Not necessarily. 'Synchronize' is not a straightforward call/return
> mechanism. It incorporates sginalling that changes thread context.
>
>> or does it
>> depend on what is in that procedure (for example using VCL) .
>
> It does depend what is in the procedure. As you obviously know, the VCL
> is
> not thread-safe.
>
>> Please consider the following:
>>
>> ----------------------------------------------
>> type
>> TForm1 = class(TForm)
>> IdTCPServer1: TIdTCPServer;
>> procedure IdTCPServer1Execute(AThread: TIdPeerThread);
>> private
>> public
>> end;
>>
>> procedure DoBlahBlah;
>>
>> var
>> Form1: TForm1;
>>
>> implementation
>>
>> procedure DoBlahBlah;
>> begin
>> // DO Something Here
>> end;
>>
>> procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
>> var
>> S : String;
>> begin
>> S := AThread.Connection.ReadLn;
>> If S = 'Blah-Blah' then
>> DoBlahBlah;
>> end;
>> --------------------------------------------
>>
>> Is this allowed?
>
> Sure. In fact you can, with some care, call methods of forms, providing
> the
> methods do not actually access VCL objects directly:
>
> --------------------------------------------
> procedure TForm1.DoBlahBlah;
> begin
> // DO Something Here that is thread-safe, eg:
> end;
>
>
> procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
> var
> S : String;
> begin
> S := AThread.Connection.ReadLn;
> If S = 'Blah-Blah' then
> DoBlahBlah;
> end;
> --------------------------------------------
>
> Rgds,
> Martin
none