procedure TForm1.Timer1Timer(Sender: TObject);
begin
TcpClient1.Active :=true;
if TcpClient1.Connected=true then
begin
label1.Caption :='连接成功';
end;
TcpClient1.Active :=false;
label1.Caption :='连接失败';
end;
为何无论是否连接到服务器都显示连接失败?
begin
TcpClient1.Active :=true;
if TcpClient1.Connected=true then
begin
label1.Caption :='连接成功';
end;
TcpClient1.Active :=false;
label1.Caption :='连接失败';
end;
为何无论是否连接到服务器都显示连接失败?
begin
TcpClient1.Active :=true;
if TcpClient1.Connected=true then
label1.Caption :='连接成功'
else
label1.Caption :='连接失败';
TcpClient1.Active :=false;
end;
begin
TcpClient1.Active :=true;
if TcpClient1.Connected then
label1.Caption :='连接成功'
else
label1.Caption :='连接失败';
TcpClient1.Active :=false;
end;
TcpClient1.Active :=true; label1.Caption :='连接成功'
except
label1.Caption :='连接失败';
end;
begin
TcpClient1.Active :=true; //连接服务器
if TcpClient1.Connected=true then
begin
label1.Caption :='连接成功'; //如果连接上了显示连接成功
end;
TcpClient1.Active :=false; //不论是否连接上了都把SOCKET关闭
label1.Caption :='连接失败'; //显示连接失败
end;你说这有可能连接上吗?连接上了后就马上被你关闭了。:)