我使用
ServerSocket1
控件做监听,当发现设置的初始端口被占用的时候就出提示信息。请问这个怎么写???
我使用try
   ServerSocket1.open;
finally
   on  E:  Exception  do  
   MessageBox(0,PChar('错误原因:'+E.message),'提示',0+16)
end;可是,还是不能捕捉错误信息??请问这个语句应该怎么写??

解决方案 »

  1.   

    try
    ServerSocket1.open;exceptionon  E:  Exception  do  
       MessageBox(0,PChar('错误原因:'+E.message),'提示',0+16)end;
      

  2.   

    try
    ServerSocket1.open;excepton  E:  Exception  do  
       MessageBox(0,PChar('错误原因:'+E.message),'提示',0+16)end;
      

  3.   

    你放在ServerSocket1的OnError事件里,看看!
      

  4.   

    try
    ...
    exception on  E:  Exception  do  
    ..
    end;
      

  5.   

    赞同lovefox_zoe(爱情狐狸) 的说法
    不过还有一点,就是异常在调试的时候要跳出的还是会跳出,调试的时候只要能显示MessageBox(0,PChar('错误原因:'+E.message),'提示',0+16)说明已经成功了
      

  6.   

    ServerSocket1.Port :=1000;
    try
       ServerSocket1.Open ;
    except
       on E: Exception do
       MessageBox(0,PChar('错误原因:'+E.message),'提示',0+16);我是这样写的,目的是如果1000这个端口被占用,那么就提示结果还是不行,生成exe后,还是不能将错误信息弹出后来我用ServerSocket1ClientError,
    procedure TFormClient.ServerSocket1ClientError(Sender: TObject;
      Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
      var ErrorCode: Integer);
    begin
        showmessage('Error');
    end;结果即使端口被占用,出现错误,但是,上边这个过程还是不能showmessage麻烦各位好心人帮我试试
      

  7.   

    ServerSocket1.Port :=1000;
    try
       ServerSocket1.Open ;
    except
       on E: Exception do
       MessageBox(0,PChar('错误原因:'+E.message),'提示',0+16);
    走不到MessageBox(0,PChar('错误原因:'+E.message),'提示',0+16);
    嘛???
      

  8.   

    ★确实的,走不到MessageBox的位置??---------->>>>>>
      

  9.   

    看对应代码  WSAEINTR              10004  Interrupted system call. 
      WSAEBADF              10009  Bad file number. 
      WSEACCES              10013  Permission denied. 
      WSAEFAULT             10014  Bad address. 
      WSAEINVAL             10022  Invalid argument. 
      WSAEMFILE             10024  Too many open files. 
      WSAEWOULDBLOCK        10035  Operation would block. 
      WSAEINPROGRESS        10036  Operation now in progress. This error is 
                                      returned if any Windows Sockets API 
                                      function is called while a blocking 
                                      function is in progress. 
      WSAEALREADY            10037  Operation already in progress. 
      WSAENOTSOCK            10038  Socket operation on nonsocket. 
      WSAEDESTADDRREQ        10039  Destination address required. 
      WSAEMSGSIZE            10040  Message too long. 
      WSAEPROTOTYPE          10041  Protocol wrong type for socket. 
      WSAENOPROTOOPT         10042  Protocol not available. 
      WSAEPROTONOSUPPORT     10043  Protocol not supported. 
      WSAESOCKTNOSUPPORT     10044  Socket type not supported. 
      WSAEOPNOTSUPP          10045  Operation not supported on socket. 
      WSAEPFNOSUPPORT        10046  Protocol family not supported. 
      WSAEAFNOSUPPORT        10047  Address family not supported by protocol 
                                      family. 
      WSAEADDRINUSE          10048  Address already in use. 
      WSAEADDRNOTAVAIL       10049  Cannot assign requested address. 
      WSAENETDOWN            10050  Network is down. This error may be 
                                      reported at any time if the Windows 
                                      Sockets implementation detects an 
                                      underlying failure. 
      WSAENETUNREACH         10051  Network is unreachable. 
      WSAENETRESET           10052  Network dropped connection on reset. 
      WSAECONNABORTED        10053  Software caused connection abort. 
      WSAECONNRESET          10054  Connection reset by peer. 
      WSAENOBUFS             10055  No buffer space available. 
      WSAEISCONN             10056  Socket is already connected. 
      WSAENOTCONN            10057  Socket is not connected. 
      WSAESHUTDOWN           10058  Cannot send after socket shutdown. 
      WSAETOOMANYREFS        10059  Too many references: cannot splice. 
      WSAETIMEDOUT           10060  Connection timed out. 
      WSAECONNREFUSED        10061  Connection refused. 
      WSAELOOP               10062  Too many levels of symbolic links. 
      WSAENAMETOOLONG        10063  File name too long. 
      WSAEHOSTDOWN           10064  Host is down. 
      WSAEHOSTUNREACH        10065  No route to host. 
      WSASYSNOTREADY         10091  Returned by WSAStartup(), indicating that 
                                      the network subsystem is unusable. 
      WSAVERNOTSUPPORTED     10092  Returned by WSAStartup(), indicating that 
                                      the Windows Sockets DLL cannot support 
                                      this application. 
      WSANOTINITIALISED      10093  Winsock not initialized. This message is 
                                      returned by any function except 
                                      WSAStartup(), indicating that a 
                                      successful WSAStartup() has not yet been 
                                      performed. 
      WSAEDISCON             10101  Disconnect. 
      WSAHOST_NOT_FOUND      11001  Host not found. This message indicates 
                                      that the key (name, address, and so on) 
                                      was not found. 
      WSATRY_AGAIN           11002  Nonauthoritative host not found. This 
                                      error may suggest that the name service 
                                      itself is not functioning. 
      WSANO_RECOVERY         11003  Nonrecoverable error. This error may 
                                      suggest that the name service itself is 
                                      not functioning. 
      WSANO_DATA             11004  Valid name, no data record of requested 
                                      type. This error indicates that the key 
                                      (name, address, and so on) was not found.
      

  10.   

    ServerSocket.Active := True
    激活,否则不行最好用
    try
    ...
    Except
    ...