Solved

Disconnected Exception

Posted on 2004-04-09
10
575 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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