这段代码供你参考:是写在TClientSocket的OnError中的。
var
i:integer;
begin
Screen.Cursor:=crdefault;
case ErrorCode of
10053:
begin
c.Socket.Close ;
Tray1.ShowBalloonHint('错误','你与服务器的连接已断开!',bhiError);
ErrorCode:=0;
for i:=0 to GPFriend.Items.Count-1 do
begin
GPFriend.Items[i].Enabled:=false;
end;
end;
10060:
begin
if assigned(frmconfig) then
if assigned(frmconfig.c) then
begin
frmconfig.c.Close;
frmconfig.c.free;
end;
Tray1.ShowBalloonHint('错误','网络上不存在该IP地址请重新设置!',bhiError);
ErrorCode:=0;
end;
10061:
begin
if assigned(frmconfig) then
if assigned(frmconfig.c) then
begin
frmconfig.c.Close;
frmconfig.c.free;
end;
Tray1.ShowBalloonHint('错误','服务器没有启动,请检查系统设置!',bhiError);
IsSrvStart:=false;
ErrorCode:=0;
end;
end;
end;