Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Mar : Re: Indy10 - TIdTCPConnection, Open/Close, ReadLnTimedOut, Read Thread

www.cryer.info
Managed Newsgroup Archive

Re: Indy10 - TIdTCPConnection, Open/Close, ReadLnTimedOut, Read Thread

Subject:Re: Indy10 - TIdTCPConnection, Open/Close, ReadLnTimedOut, Read Thread
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Fri, 30 Mar 2007 10:57:08

"Michael Stieler" <michael@stieler.it> wrote in message
news:460d4a04@newsgroups.borland.com...

> What if the read thread finishes because its own while
> condition not met?

It does not matter why the thread exits from its Execute() method.
Once Execute() has exited, the thread is effectly finished and
WaitFor() can then return immediately afterwards.

> Does it harm to call .Terminate on it after this when
.FreeOnTerminate = false?

All the Terminate() method does it sets the Terminated property to
true.  It does not do anything else.

> I once had the impression that .WaitFor didn't return if the
> thread is already finished.

Yes, it does.

> You wanted to put the conn.Connect inside the try..except block,
> didn't you?

No, I did not.  I intentionally left it out.  If Connect() fails, an
exception is raised.  There is no point in creating the thread when
that happens, and the code snippet I showed you is not providing any
other way of reporting whether Connect() failed, so I am letting the
exception escape into the calling code for the application to handle
as it sees fit.  The only reason to put Connect() inside the
try..except block would be if the Connect() method had a Boolean
return value instead, ie:

    function TMyComp.Connect: Boolean;
    begin
        Result := False;
        conn.Host := ...
        conn.Port := ...
        try
            conn.Connect;
            try
                readThread := TReadThread.Create(conn);
                readThread.OnRead := Read;
                readThread.Resume;
            except
                conn.Disconnect;
                raise;
            end;
            Result := True;
        except
        end;
    end;


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive