Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delphi 7 IdFTP client error message

Posted on 2003-10-27
4
Medium Priority
?
4,491 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 1350 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

618 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