Solved

Delphi 7 IdFTP client error message

Posted on 2003-10-27
4
4,191 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
  • 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
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…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 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

20 Experts available now in Live!

Get 1:1 Help Now