UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Extctrls;typeTMY=class(TThread) PublicThreadend:boolean; ConstructorCreate ();Overload; destructor Destroy();Overload; procedureExecuteOverride; End; TForm1=class(tform) Button1:tbutton; Panel1:tpanel; Button2:tbutton; Panel2:tpanel; procedureButton1Click (Sender:tobject); procedureButton2click (Sender:tobject); Private {Private Declarations}my:tmy; Public {Public Declarations} End;varForm1:tform1;Implementation{$R *.DFM}Constructortmy.create ();beginThreadend:=False; Freeonterminate:=True;inherited Create(False);End;destructorTMY.Destroy();begin inherited Destroy;End;procedureTmy.execute;varI:integer;begin forI: =1 to the Do beginSleep (1); Form1.Panel1.Caption:= IntToStr (i);End; Threadend:=True; End;procedureTform1.button1click (sender:tobject);beginMy:= Tmy.create;//Execution ThreadEnd;procedureTform1.button2click (sender:tobject);vari:cardinal; Isquit:boolean;beginIsquit:=getexitcodethread (My.handle,i);//Check if thread endsifIsquit Thenbutton2.caption:='True' Elsebutton2.caption:='False'; //My.threadend=true can also determine the end of a thread. End;End.
Delphi implementation detects if thread class TThread is over