请问我这段关于线程的代码有什么问题?

wealsh 2006-05-04 03:38:42

type
Myzhiling = record
command: Integer;
end;

ClientInfo = record
PcName:string[5];//名称
passwd:string[20];//密码
command:string[5];//指令
Ver:string[2]; //版本
Text:string; //附加信息
end;

TMyThread = class(TThread)
private
F_info:ClientInfo;
F_Athread: TIdPeerThread;
protected
procedure DoTerminate; override;
public
constructor Create(C_info:ClientInfo; const C_Athread: TIdPeerThread);
destructor Destroy; override;
procedure Execute; override;
end;

implementation

uses main;

{ TCheckThread }

constructor TMythread.Create(C_info:ClientInfo; const C_Athread: TIdPeerThread);
begin
inherited Create(False);
FreeOnTerminate := True;

F_info:=C_info;
F_Athread := C_Athread;
end;

destructor Tmythread.Destroy;
begin
inherited Destroy;
end;

procedure TMythread.DoTerminate;
begin
inherited DoTerminate;
end;

procedure TMythread.Execute;
begin
with Form1 do
begin
EnterCriticalSection(cs);
if F_info.command='ADD'then
begin
form1.listview1.items.add................
end;
LeaveCriticalSection(cs);
Terminate;
end;



//=========================

procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
C_info:ClientInfo;
begin
// if (not AThread.Terminated) and (AThread.Connection.Connected=True) then
begin
AThread.Connection.ReadBuffer(C_info,SizeOf(C_info));
TMyThread.Create(C_info,AThread);
end;
end;
...全文
105 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fanshousu 2006-05-05
  • 打赏
  • 举报
回复
在线程中访问VCL控件的时候,请使用Synchronize
按照你的上面写法,程序中Form1将会出现停止状态,这是由于Form1将不能其他的访问
qlwuu 2006-05-04
  • 打赏
  • 举报
回复
不要在主线程以外的地方访问vcl控件。

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧