Solved

Disconnected Exception

Posted on 2004-04-09
10
568 Views
Last Modified: 2010-04-05
Hi All,

Can somebody tell me how can I turn off exception when TIdTcpClient is disconnecting? It always happen in Delphi only.

Thanks.
0
Comment
Question by:dosware
  • 6
  • 4
10 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10790223
Go to Tools - Debugger options - Language Exceptions and uncheck the Stop on Delphi Exceptions checkbox
0
 

Author Comment

by:dosware
ID: 10790268
Thanks man, but I know it. I thought that it possible to use other TIdTcpClient function, not Disconnect :)
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 100 total points
ID: 10790295
OK, i've misunderstood the question....
So you can use CheckForDisconnect....

from Indy help

Determines if the peer has been disconnected.

procedure CheckForDisconnect(const ARaiseExceptionIfDisconnected: boolean = true; const AIgnoreBuffer: boolean = false); virtual;

Parameters

const ARaiseExceptionIfDisconnected: boolean = true

Raise an exception when the connection is closed. Default value is True.

const AIgnoreBuffer: boolean = false

Disregards the read buffer size. Default value is False.

Description

CheckForDisconnect is a procedure used to determine if a connection has been closed by either the server or the client.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:dosware
ID: 10790321
I've read it, but can not find example how can I use it... Do you have any?
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10790376
You can use it instead of DIsconnect

with TCPClient do
  begin
  Connect;
  try
  ListBox1.Items.Add(ReadLn);
  finally
  CheckForDisconnect(false);
  end;
  end;
0
 

Author Comment

by:dosware
ID: 10790401
I use this function for disconnect:

function StopSocket(ASocket: TIdTcpClient): Boolean;
begin
  with(ASocket)do begin
    try
      if(Connected)then Disconnect;
    finally
      Result:=Connected;
    end;
  end;
end;

All sockets uses threads for reading information. When I'm trying to change the procedure Disconnect to procedure CheckForDisconnect it always freezes.
0
 

Author Comment

by:dosware
ID: 10790422
Strange situation... Sometimes it tells me 'Not Connected' event but sometimes it tells me 'Disconnected' event... Strange!
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10790439
OK so go to this way

function StopSocket(ASocket: TIdTcpClient): Boolean;
begin
  with(ASocket)do begin
    try
      if(Connected)then
      try
         Disconnect;
      except
         //Get rid here of the exception
     end;
    finally
      Result:=Connected;
    end;
  end;
end;
0
 

Author Comment

by:dosware
ID: 10790455
Unfortunately same errors
0
 

Author Comment

by:dosware
ID: 10791175
It normally works in EXE but I need to get normally working under Delphi also therefore in debug mode it looks terribly...
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: how to send PJL commands to printer 3 99
Comparing dates in Delphi. Greater than/ Less than 3 154
Delphi Form ownership 4 89
Dynamically Created Query 3 55
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question