Unit _Main;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Type
TTestThread =
Class(TThread)
Procedure Execute;
override;
End;
TForm1 =
Class(TForm)
Label1 : TLabel; Button1 : TButton;
Button2 : TButton; Button3 : TButton;
Procedure FormCreate(Sender: TObject);
Procedure Button1Click(Sender: TObject);
Procedure Button2Click(Sender: TObject);
Procedure Button3Click(Sender: TObject);
End;
Var
Form1 : TForm1;
Exists : Boolean;
SecondProcess : TTestThread;
Implementation
{$R *.dfm}
Procedure TForm1.FormCreate(Sender: TObject);
Begin
Exists:=False;
End;
Procedure TTestThread.Execute;
Var
I : Integer;
Begin
For I:=0
To MaxInt
Do
Begin
Form1.Label1.Caption:=IntToStr(I);
If Terminated
Then
Begin
Exit;
End;
End;
Form1.Label1.Caption:='
Thread beendet.';
End;
Procedure TForm1.Button1Click(Sender: TObject);
Begin
Button1.Enabled:=False;
Button2.Enabled:=True;
Button3.Enabled:=True;
If Not Exists
Then // Thread existiert schon?
Begin
SecondProcess:=TTestThread.Create(True);
SecondProcess.Priority:=tpLower;
Exists:=True;
End;
SecondProcess.Resume;
End;
Procedure TForm1.Button2Click(Sender: TObject);
Begin
SecondProcess.Suspend;
Button1.Enabled:=True;
Button2.Enabled:=False;
Label1.Caption:='
Thread angehalten.';
End;
Procedure TForm1.Button3Click(Sender: TObject);
Begin
SecondProcess.Terminate;
Button3.Enabled:=False;
Button2.Enabled:=False;
Button1.Enabled:=True;
Exists:=False;
Label1.Caption:='
Thread beendet.';
End;
End.