I am sorry for asking such a simple question. This is the first time I am using a background thread in VCL. So I was wondering if it is safe to use local variable in Async part?
procedure Tfrm1.ThreadedFillDataset;
var
ds : TOracleDataSet;
begin
lblThread.Caption := 'Thread start';
Async(
procedure
begin
// executed in background thread
//Sleep(3000);
ds := TOracleDataSet.Create(Self);
//SetVariables
ds.Open;
end)
.Await(
procedure
begin
ds.First;
while not ds.Eof do
begin
//Fill design time dataset on form
ds.Next;
end;
ds.Free;
lblThread.Caption := 'Thread finished';
end);
end;
Suppose that I execute this method three times, without first thread being completed. Would this lead to problems?
Would you suggest another approach to this problem? (Using background thread to query database, append results into a VCL dataset.)
Thanks.
Edit: I have examined the answer to question 13348970 which my question was marked a duplicate of. I have come to conclude that if my method is invoked 3 different times, all 3 ds
local variables will point to a different memory adress, therefore each thread will access its local copy of TOracleDataSet and there will be no problems. If someone can confirm this I can close the question, thank you.