unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;typeTMyThread = class(TThread) private { Private declarations } procedure AddTh; procedure DecTh; protected procedure Execute; override; end; TForm1 = class(TForm) Edit1: TEdit; Timer1: TTimer; Button1: TButton; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } ThCounter:integer; end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);begin ThCounter:=0;end;{ TMyThread }procedure TMyThread.AddTh;begin Form1.ThCounter:= Form1.ThCounter +1; Form1.Edit1.Text:= intToStr(Form1.ThCounter);end;procedure TMyThread.DecTh;begin Form1.ThCounter:= Form1.ThCounter -1; Form1.Edit1.Text:= intToStr(Form1.ThCounter);end;procedure TMyThread.Execute;var i:integer;begin inherited; Synchronize(AddTh); sleep(10000); Synchronize(DecTh);end;procedure TForm1.Timer1Timer(Sender: TObject);var th:TMyThread;beginif(Form1.ThCounter<5) thenbegin th:= TMyThread.Create(true); th.FreeOnTerminate:=true; th.Resume(); end;end;procedure TForm1.Button1Click(Sender: TObject);beginTimer1.Enabled:=true;end;end.