uses System.Classes,
System.Generics.Collections;
var
Nums: TList<Integer>;
Thread: TThread;
N: Integer;
begin
Nums := TList<Integer>.Create;
Nums.AddRange([1, 2, 3]);
//the list is captured by the
//anonymous procedure
Thread := TThread.CreateAnonymousThread(
procedure
var
Value: Integer;
begin
Write('child thread: ');
for Value in Nums do
Write(Value, ' ');
WriteLn;
end);
Thread.FreeOnTerminate := False;
Thread.Start;
Thread.WaitFor;
Thread.Free;
Nums.Add(4);
Write('main thread: ');
for N in Nums do
Write(N, ' ');
WriteLn;
end.