我对如何将唯一标识符存储在动态创建的TThread
.
我创建了这样的东西:
procedure TForm1.Button1Click(Sender: TObject);
var thrn:word;
begin
for thrn := 0 to 5 do//<--- this is a loop variable that should give the unique numbers
TThread.CreateAnonymousThread(
procedure()
var
i: longint;
r: double;
thrns:string;
begin
thrns:=inttostr(thrn);//in this thread? variable I try to store the ID as string
repeat
for i := 0 to 100000000 do
begin
r := random(high(i));//this loop gives some dummy job
r := sqr(r); //to the thread to slow it down
end;
TThread.Synchronize(nil,
procedure()
begin
memo1.Text:=memo1.Text+#13#10+
'done'+thrns;//it returns strange IDs including '6'
end);
until false;
end).Start;
end;
我可以将唯一标识符传递给动态创建的线程,以便它可以在其同步方法中显示它吗?