Solved

Disconnected Exception

Posted on 2004-04-09
10
566 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now