Link to home
Start Free TrialLog in
Avatar of Skyruner2
Skyruner2

asked on

Delphi 7 IdFTP client error message

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?


ASKER CERTIFIED SOLUTION
Avatar of alsantos
alsantos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Skyruner2
Skyruner2

ASKER

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