form上放一个edit,一个button,一个ClientSocket 以下代码,错在哪里?procedure TForm1.Button1Click(Sender: TObject);
begin
if ClientSocket.Active then ClientSocket.Close;
ClientSocket.Host:=edit1.text;
try
ClientSocket.Open;
if ClientSocket.Active then
MessageDlg(‘Connect OK‘,mtInformation, [mbOk], 0);
except
on ESocketError do MessageDlg(‘error‘,mtInformation, [mbOk], 0);
end;
if ClientSocket.Active then ClientSocket.Close;
end;
begin
if ClientSocket.Active then ClientSocket.Close;
ClientSocket.Host:=edit1.text;
try
ClientSocket.Open;
if ClientSocket.Active then
MessageDlg(‘Connect OK‘,mtInformation, [mbOk], 0);
except
on ESocketError do MessageDlg(‘error‘,mtInformation, [mbOk], 0);
end;
if ClientSocket.Active then ClientSocket.Close;
end;
MessageDlg('error',mtInformation, [mbOk], 0);试试
...
except
on ex:exception do
showmessage(ex.message);
end;
如果在程序运行中没有异常提示,那说明确实没有异常,因为Delphi程序始终包含在一个大的
try...except..结构中的,ClientSocket.Open失败的信息也许使用另外的方式来返回。如果程序中有异常提示,那说明异常异常没有发生在你设置的try范围内。