unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,syncobjs;
type TmyThread=class(TThread)
public
procedure go;
private
protected
procedure execute;
override;
end;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Edit1: TEdit;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
Anzeige:TMyThread ;
end;
var
Form1: TForm1;
i:integer;
a,b:boolean;
event:TEvent;
implementation
{$R *.dfm}
procedure TmyThread.execute;
//var event:TEvent;
begin
//Zugriff aus dasselbe Event
event:=TEvent.Create(
nil,true,false,'
myEvent');
while(
not terminated)
do
begin
event.waitfor(infinite);
//mach etwas
i:=i+1;
sleep(100);
form1.Edit1.Text:=inttostr(i);
Synchronize(go);
end;
event.free;
end;
procedure TmyThread.go;
begin
if a=false
then
event:=TEvent.Create(
nil,true,false,'
myEvent');
form1.Edit1.Text:=inttostr(i);
end;
procedure TForm1.Button1Click(Sender: TObject);
var thread:TmyThread;
begin
label1.Caption:='
warte';
//event:=TEvent.Create(nil,true,false,'myEvent'); //Event anlegen (mit Namen)
with Tmythread.Create(true)
do //Thread starten
begin
FreeOnTerminate:=true;
resume;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
event.SetEvent;
event.Free;
a:=true;
end;
procedure TForm1.Button3Click(Sender: TObject);
// Schleife anhalten bzw. Event anlegen!
begin
a:=false;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
a:=true;
end;
end.