Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Apr : Re: tidclient disconnect close problem

www.cryer.info
Managed Newsgroup Archive

Re: tidclient disconnect close problem

Subject:Re: tidclient disconnect close problem
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Mon, 16 Apr 2007 09:11:09

"mustafa korkmaz" <none@none.com> wrote in message
news:46220cef$1@newsgroups.borland.com...

> if the user dont use this button and try to close the program the
> program can not be closed or freeze. It can be closed only
> task manager.

Then you are doing something wrong in your code that is using Indy.

> Is there any wrong line below?

A thread should NEVER assign a handler to its own OnTerminate event
like that.

But beyond that, one thing I do see is that if the server disconnects
the connection, your code is going to end up calling Disconnect()
twice on the connection.  Try calling Connected() before calling
Disconnect(), ie:

    if ClientThread <> nil then ClientThread.Terminate;
    try
        if TCPClient.Connected then // <-- here
            TCPClient.Disconnect;
    finally
        if ClientThread <> nil then
        begin
            ClientThread.WaitFor;
            FreeAndNil(ClientThread);
        end;
    end;

> procedure TfrmMainform.TcpClientDisconnected(Sender: TObject);
> begin
>  waittimer1.enabled := true;
> //if I dont use timer the program freeze on
"ClientThread.WaitFor();" line.
> end;

You shouldn't be calling Disconnect() at all from inside the
OnDisconnect event handler.  OnDisconnect is triggered inside of
Disconnect(), so you are likely causing an endless recursion loop.
I'm surprised you are not seeing a stack overflow exception occuring.


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive