代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
start: TButton;
Memo1: TMemo;
procedure startClick(Sender: TObject);
*******
{ Private declarations }
public
{ Public declarations }
end;
TMyThread = class(TThread)
*******
FMyThreadID:integer;
public
constructor Create(CreateSuspended:Boolean;MyThreadID:integer);overload;
procedure execute;override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.startClick(Sender: TObject);
var
i: integer;
TestThread: TMyThread;
begin
for i:=0 to 9 do
begin
TestThread:=TMyThread.Create(false,i+1);
end;
end;
constructor TMyThread.Create(CreateSuspended:Boolean;MyThreadID:integer);
begin
inherited Create(CreateSuspended);
FMyThreadID:=MyThreadID;
end;
procedure TMyThread.execute;
begin
//Showmessage('线程'+IntToStr(FMyThreadID));
form1.Memo1.Text:= '线程'+IntToStr(FMyThreadID);
end;
end.
源代码下载:http://www.rayfile.com/files/0b539d40-1320-11df-803b-0015c55db73d/