Delphi implementation detects if thread class TThread is over

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.