我是主动关闭FTP链接的,然后链接时就提示 ‘socket error #10061’,这类错误信息如果才可以修改为自定义信息 ? 网上说捕获 Errorcode再通过 if 语句修改,但是不知道怎样才能够捕获 Errorcode。另外 IdFTP1.Connect(); 也不能够通过 try  except end 做相应的判断机制。

解决方案 »

  1.   


      try
        idftp1.Connect;
      except
        on e: EIdSocketError do
        begin
          ShowMessage(IntToStr(e.LastError));
        end;
      end;  
      

  2.   

    可以使用Application.OnException事件
    Application.OnException := ApplicationException;procedure TFormMain.ApplicationException(Sender: TObject; E:Exception);
    begin
    ......
    end;
      

  3.   


    报如下这个错误 哦!
    [dcc32 Error] Main.pas(74): E2003 Undeclared identifier: 'ApplicationException'
      

  4.   

      try
        idftp1.Connect;
      er:=getlasterror()
      except
       if er=10061 then
        begin
             showmessage('朋友好久见,联系不上')
        end
    else
        begin
          showmessage('尊敬的顾客,还有什么事可帮您')
         end
      end; 
      

  5.   


    unit Unit1;interfaceuses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
      System.Classes, Vcl.Graphics,  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        procedure ApplicationException(Sender: TObject; E:Exception);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      Application.OnException := ApplicationException;
    end;procedure TForm1.ApplicationException(Sender: TObject; E:Exception);
    begin
      if (Pos('Socket Error # 10061', E.Message ) >= 1) then
      begin
        Application.MessageBox(
          PChar('连接已中断(' + E.Message + ')'),
          PChar('报错信息'), MB_OK + MB_ICONSTOP + MB_TOPMOST);
      end
      else
        Application.ShowException(E);
    end;end.