看我的例子。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TAddThread =class(TThread)
Flag:integer;
constructor Create(in_flag:integer);
procedure Execute;
override;
end;
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TAddThread }
constructor TAddThread.create(in_flag:integer);
begin
inherited Create(True);
FreeOnTerminate:=True;
Suspended:=false;
Flag:=In_flag;
end;
procedure TAddThread.Execute;
var
i:integer;
begin
for i:=0 to 50do
begin
form1.Memo1.Lines.Add('Thread ['+inttostr(Flag)+'] line '+inttostr(i));
sleep(300);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
AddThread:TaddThread;
i:integer;
begin
for i:=0 to 4do
begin
AddThread:=TaddThread.Create(i);
end;
end;
end.
不好意思,多了FORMCREATE,我把它删除了。