I have multithread application.
procedure TGridUpdater.Execute;
begin
inherited;
CodeSite.Send('Thread executed');
sp := ConnectionFactory.GetConnection.LoadStoredProc('rab_itemData');
sp.CreateParam('Tahun', ftInteger, sppdInput).Value := _form.tahun;
sp.Open;
Synchronize(DoProgress1);
sp.DataSet.First;
I := 0;
CodeSite.Send('Terminated value is ' + BoolToStr(Terminated)); //The terminated property is 'True' here. Why?
while (not Terminated) and (not sp.DataSet.Eof) do
begin
CodeSite.Send('Entering loop');
Synchronize(DoProgress);
I := I + 1;
sp.DataSet.Next;
end;
Synchronize(DoProgress2);
end;
Method to run thread
procedure TFRABData.RefreshDataset;
var
GridUpdater: TGridUpdater;
begin
GridUpdater := TGridUpdater.Create(True);
GridUpdater.OwnerForm := Self;
GridUpdater.Start;
CodeSite.Send('RefreshDataset executed');
GridUpdater.Free;
end;
You are freeing your thread immediately after you start it. You have to let it live its own life. So to answer your question, it's the thread's destructor that sets the Terminated
flag to True.
procedure TFRABData.RefreshDataset;
var
GridUpdater: TGridUpdater;
begin
GridUpdater := TGridUpdater.Create(True);
GridUpdater.OwnerForm := Self;
GridUpdater.Start;
CodeSite.Send('RefreshDataset executed');
GridUpdater.Free; // <-- don't do this; let the thread live its own life
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With