Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Dec : Re: how to check connection?

www.cryer.info
Managed Newsgroup Archive

Re: how to check connection?

Subject:Re: how to check connection?
Posted by:"soonic" (xxsoon..@op.pl)
Date:Sat, 29 Dec 2007 21:43:02

> Wrap the Disconnect() in a try..except or try..finally so the thread is
> still terminated and freed:

I get quickly error when I just press a button to disconnect:
'....raised exception class EIdClosedSocket with message Disconnected...'

procedure TMainForm.DiconBtnClick(Sender: TObject);
begin
   DisconnectServer;
end;

'netunit.pas'
procedure DisconnectServer;
begin
  with MainForm do
  begin
     if IdTCPServer.Active then IdTCPServer.Active := False;
    ....
   end;

   if ReadingThread <> nil then
   begin
     ReadingThread.Terminate;
     try
       MainForm.IdTCPClient.Disconnect;
     finally
       ReadingThread.WaitFor;
       FreeAndNil(ReadingThread);
     end;
   end;
end;

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive