Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Disconnected Exception

Posted on 2004-04-09
10
Medium Priority
?
585 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 23

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 23

Accepted Solution

by:
Ferruccio Accalai earned 300 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 23

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 23

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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

971 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