L
lebronjames
Unregistered / Unconfirmed
GUEST, unregistred user!
目前的开发需要用多线程,我只好临时报佛脚求助于各位大侠了呵呵
问题:如何启用多线程.
描述:是这样的,要求2个memo组件里面不断生成一些字符串,要求用多线程技术实现,2个MEMO同时工作
代码://
unit Unit1;
......
implementation
uses unit2;
var thread1:tb;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
/////////////////////////请问这个按钮的事件如何启动tb这个线程正常工作呢????
////////////////////////
end;
end.
///线程
unit Unit2;
......
type
tb = class(TThread)
private
{ Private declarations }
protected
procedure Execute;
override;
public
constructor create;
end;
implementation
uses unit1;
constructor tb.create;
begin
inherited create(false);
end ;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure tb.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ tb }
procedure tb.Execute;
var
i:integer;
begin
for i:=0 to 9999do
begin
memo1.lins.add(inttostr(i));
end;
{ Place thread code here }
end;
end.
请大家指点一下!谢谢谢谢
问题:如何启用多线程.
描述:是这样的,要求2个memo组件里面不断生成一些字符串,要求用多线程技术实现,2个MEMO同时工作
代码://
unit Unit1;
......
implementation
uses unit2;
var thread1:tb;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
/////////////////////////请问这个按钮的事件如何启动tb这个线程正常工作呢????
////////////////////////
end;
end.
///线程
unit Unit2;
......
type
tb = class(TThread)
private
{ Private declarations }
protected
procedure Execute;
override;
public
constructor create;
end;
implementation
uses unit1;
constructor tb.create;
begin
inherited create(false);
end ;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure tb.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ tb }
procedure tb.Execute;
var
i:integer;
begin
for i:=0 to 9999do
begin
memo1.lins.add(inttostr(i));
end;
{ Place thread code here }
end;
end.
请大家指点一下!谢谢谢谢