File->New->Other中可以选择TThread Objects 即创建了一个包含线呈的单元(设为unit2如下) unit Unit2; interface uses Classes;type MyThread = class(TThread) private { Private declarations } protected procedure Execute; override; end;implementation{ 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 MyThread.UpdateCaption; begin Form1.Caption := 'Updated in a thread'; end; }{ MyThread }procedure MyThread.Execute; begin //在这里编写代码即可 end;end.
即创建了一个包含线呈的单元(设为unit2如下)
unit Unit2;
interface
uses
Classes;type
MyThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;implementation{ 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 MyThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }{ MyThread }procedure MyThread.Execute;
begin
//在这里编写代码即可
end;end.
MyThread.create(false);//创建线呈并使其立即执行