怎么编写idtcpclient接收数据的线程
1个回答
展开全部
关闭程序最好断开连接,停止监听
用Synchronize来和主线程同步
procedure TRecvThread.HandleShow;
begin
Form1.Memo1.Lines.Add(str);
end;
procedure TRecvThread.Execute;
var
str:string;
begin
if not form1.IdTCPClient1.Connected then
terminate;
while (not Terminated) and form1.IdTCPClient1.Connected do
begin
str:=form1.IdTCPClient1.ReadLn;
Synchronize(HandleShow);
end;
end;
用IdTCPClient1.Disconnect断开连接
然后 停止Server的监听
用Synchronize来和主线程同步
procedure TRecvThread.HandleShow;
begin
Form1.Memo1.Lines.Add(str);
end;
procedure TRecvThread.Execute;
var
str:string;
begin
if not form1.IdTCPClient1.Connected then
terminate;
while (not Terminated) and form1.IdTCPClient1.Connected do
begin
str:=form1.IdTCPClient1.ReadLn;
Synchronize(HandleShow);
end;
end;
用IdTCPClient1.Disconnect断开连接
然后 停止Server的监听
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询