Solved

Delphi 7 IdFTP client error message

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Title # Comments Views Activity
Delphi - replicating a form 8 86
Printing problem 2 102
select query - oracle 16 100
Delphi...Split view - idea? 1 90
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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 shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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