[DUG] Terminating a thread

Nick Fauchelle nick at unica.co.nz
Thu Sep 21 11:43:16 NZST 2006


Hey guys,

I got a thread here (TFetchData = class(TThread)) which downloads a 
bunch of xml and then process's it and sticks it into a database.
All working well, however I want the user to be able to abort/terminate 
the process...

So one think I did is setup a global varaible - gbTerm : boolean;
And in my thread.execute I would do this
If gbTerm = true then terminate;

However that didn't quite work as expected (ie, nothing happened, thread 
still ran).

So then I tried

var
MyThread : TFetchData;
begin
MyThread := TFetchData.create('myname');
end;

button2
begin
MyThread.Terminate;
end;

same result as above (to be expected ofc).

So im just wondering... how should I terminate this thread?

Thanks
Nick


More information about the Delphi mailing list