private
{ Private declarations }
sysAbort:Boolean ;
procedure TForm3.button_StartClick(Sender: TObject);
var
sysNum:Integer ;
begin
sysAbort:=False ;
sysNum:=0 ;
memo1.lines.add('Starting') ;
with TThread.CreateAnonymousThread(
procedure
var
MaxValue:Int64 ;
I: Integer;
Total: Integer;
begin
MaxValue:=1000 ;
for I := 1 to MaxValue do
begin
if sysAbort then // Can I use thus ?
break ;
sysNum:=I ; // Can I use local variable
// memo1.lines.Add('Violated ' + Inttostr(sysNum)) ; // This works too !
if (I * 10 mod MaxValue) = 0 then
TThread.Synchronize (TThread.CurrentThread,
procedure ()
begin
memo1.lines.Add('Progress : ' + Inttostr(I)) ;
end);
sleep(10) ; // just for delay
end;
TThread.Synchronize (TThread.CurrentThread,
procedure ()
begin
memo1.lines.Add('End of process : ' + IntToStr(sysNum));
end);
end
) do
begin
OnTerminate := ThreadFinished ;
Start;
end;
end;
procedure TForm3.ThreadFinished(Sender: TObject);
begin
if TThread(Sender).FatalException = nil then begin
TThread.Queue(nil,
procedure
begin
memo1.lines.Add('Via Queue after Finish');
end
);
end;
end;
procedure TForm3.button_AbortClick(Sender: TObject);
begin
sysAbort:=True ;
end;
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE