为什么这个线程只需要在indy客户端connect的时候创建一下,然后就可以一直不断的接收服务器的消息?
难道这个线程运行一次不就销毁了么?为什么一直会存在呢?
procedure TMainThread.Foo;
var
Msg:string;
bool: boolean;
begin
bool:=true;
while bool do begin
try
Msg:= Form6.IdTCPClient1.IOHandler.ReadLn;
if(Msg='') then
bool:=false
else
begin
M_Lock.Enter;
M_MsgList.Add(Msg);
M_Lock.Leave;
end;
except
bool:=false;
end;
end;
end;Procedure TMainThread.Execute;//线程启动
begin
FreeOnTerminate:=True;
Foo;
End;
End.
难道这个线程运行一次不就销毁了么?为什么一直会存在呢?
procedure TMainThread.Foo;
var
Msg:string;
bool: boolean;
begin
bool:=true;
while bool do begin
try
Msg:= Form6.IdTCPClient1.IOHandler.ReadLn;
if(Msg='') then
bool:=false
else
begin
M_Lock.Enter;
M_MsgList.Add(Msg);
M_Lock.Leave;
end;
except
bool:=false;
end;
end;
end;Procedure TMainThread.Execute;//线程启动
begin
FreeOnTerminate:=True;
Foo;
End;
End.
如果msg为空值,就退出循环。
多会这个会为空值呢?
if(Msg='') then
bool:=false