Solved

Delphi 7 IdFTP client error message

Posted on 2003-10-27
4
4,381 Views
Last Modified: 2012-05-04
hi,
when there is an error with the IdFTP client, nothing happens in the compiled exe. In the Debugger i get an error message such as 11004 if the host cannot be found, or a similar message with a wrong Username, or password.

here is my code:

begin
If InternetGetConnectedState(nil, 0) = true then
begin
  IdFTP1.Host:=EditHost.Text;
  IdFTP1.Username:=EditUser.Text;
  IdFTP1.Password:=EditPass.Text;
    try
      IdFTP1.Connect;
    except
      {on EIdProtocolReplyError do showmessage('hi');} - I got this from the debugger exception error message
    end;
IdFTP1.quit
end
Else
showmessage('Not Connected');
end;

the on EId.. do showmessage is in {} because the compiler does not know the error. or so it says.

it is listed in delphi/source/indy/exception.pas
{ EIdProtocolReplyError }

constructor EIdProtocolReplyError.CreateError(const AErrCode: Integer;
  const AReplyMessage: string);
begin
  inherited Create(AReplyMessage);
  FReplyErrorCode := AErrCode;
end;

so how can i catch the exceptions/error to let the client/exe user know what happened?


0
Comment
Question by:Skyruner2
[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
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
alsantos earned 450 total points
ID: 9629288
Hi Skyruner2, I don't understand the IdFTP1.quit; It will be executed everytime, when you connect successful and when you got a error message.
 
begin
If InternetGetConnectedState(nil, 0) = true then
begin
  IdFTP1.Host:=EditHost.Text;
  IdFTP1.Username:=EditUser.Text;
  IdFTP1.Password:=EditPass.Text;
    try
      IdFTP1.Connect;
    except
      on E: EIdProtocolReplyError do
         showmessage(E.Message);
    end;
  IdFTP1.quit
  end
  Else
  showmessage('Not Connected');
end;

or you can use this:

begin
If InternetGetConnectedState(nil, 0) = true then
begin
  IdFTP1.Host:=EditHost.Text;
  IdFTP1.Username:=EditUser.Text;
  IdFTP1.Password:=EditPass.Text;
    try
      IdFTP1.Connect;
    except
      on E: Exception do
         showmessage(E.Message);
    end;
  IdFTP1.quit
  end
  Else
  showmessage('Not Connected');
end;

alsantos
0
 

Author Comment

by:Skyruner2
ID: 9629772
seems to work..

how can i change the "socket error 11004" to something "more constrictive", like invalid host?
and If e.message = 'bla' didnt seem to work.. :(


as for the  IdFTP1.quit ... its just because i havn't added anything inbetween.. lol i just whanted to see if my connection even worked.
0
 
LVL 2

Expert Comment

by:alsantos
ID: 9629879
You can use something like this:

  try
    idTCPClient1.Connect;
  except
    on E: Exception do
      if Pos('Connection refused', E.Message) > 0 then
        showmessage('Conection Refused.')  // it will only show connection refused for error that have Connection refused on E.Message
      else showmessage(E.Message); // and if not have connection refused on E.Message , show the E.Message
                                                  // so you can do an if to all cases you want
    end;


  or you can do an except for all cases

  try
    idTCPClient1.Connect;
  except
     on E: EIdProtocolReplyError do
        showmessage('The error message you want for this error.');
     on E: SomeError do  // this SomeError must exist.
         showmessage('some other error');
    on E: Exception do
         showmessage(E.Message);
    end;

alsantos
0
 
LVL 2

Expert Comment

by:alsantos
ID: 9629889
you can replace 'Connection refused' by the words you want to search and if found, it will show your custom message
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

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…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

689 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