unit Frm_Main;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Vcl.ExtCtrls, TMyThreadUnit;
type
TForm1 =
class(TForm)
lbl_eins: TLabel;
lbl_zwei: TLabel;
btn_eins: TButton;
btn_zwei: TButton;
lbl_Zeit: TLabel;
Timer1: TTimer;
Timer_Eins_Start: TButton;
Timer_Zwei_Start: TButton;
Timer_Eins_Pause: TButton;
Timer_Zwei_Pause: TButton;
Timer_Eins_Resume: TButton;
Timer_Zwei_Resume: TButton;
Timer_Eins_Stop: TButton;
Timer_Zwei_Stop: TButton;
btn_EinsZwei: TButton;
procedure btn_einsClick(Sender: TObject);
procedure btn_zweiClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer_Eins_StartClick(Sender: TObject);
procedure Timer_Eins_ResumeClick(Sender: TObject);
procedure Timer_Eins_StopClick(Sender: TObject);
procedure Timer_Zwei_StartClick(Sender: TObject);
procedure Timer_Eins_PauseClick(Sender: TObject);
procedure Timer_Zwei_PauseClick(Sender: TObject);
procedure Timer_Zwei_ResumeClick(Sender: TObject);
procedure Timer_Zwei_StopClick(Sender: TObject);
procedure btn_EinsZweiClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
//Alles im Main-Thread
procedure Timer_Eins;
procedure Timer_Zwei;
//Wird vom MyThread aufgerufen
procedure Write_Counter_Eins(Counter_Eins: integer);
procedure Write_Counter_Zwei (Counter_Zwei: integer);
procedure Write_Uhr (Zeit: TTime);
end;
var
Form1: TForm1;
implementation
//uses TMyThreadUnit;
{$R *.dfm}
procedure TForm1.btn_einsClick(Sender: TObject);
begin
Timer_Eins;
end;
procedure TForm1.btn_zweiClick(Sender: TObject);
begin
Timer_Zwei;
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
TH_Uhr.Free;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
TH_Uhr := TMyThread_Uhr.Create(False);
end;
procedure TForm1.btn_EinsZweiClick(Sender: TObject);
begin
TH_Eins := TMyThread_Eins.Create(False);
TH_Zwei := TMyThread_Zwei.Create(False);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
lbl_Zeit.Caption := TimeToStr(now());
end;
procedure TForm1.Timer_Eins;
var I: integer;
sEins: integer;
c_Eins: integer;
begin
sEins := 1000;
c_Eins := 0;
lbl_eins.Caption := IntToStr(c_Eins);
lbl_eins.Refresh;
for I := 0
to 9
do begin
sleep(sEins);
INC(c_Eins);
lbl_eins.Caption := IntToStr(c_Eins);
lbl_eins.Refresh;
end;
end;
procedure TForm1.Timer_Zwei;
var I: integer;
sZwei: integer;
c_Zwei: integer;
begin
sZwei := 1000;
c_Zwei := 0;
lbl_zwei.Caption := IntToStr(c_Zwei);
lbl_zwei.Refresh;
for I := 0
to 9
do begin
sleep(sZwei);
INC(c_Zwei);
lbl_zwei.Caption := IntToStr(c_Zwei);
lbl_zwei.Refresh;
end;
end;
procedure TForm1.Timer_Eins_PauseClick(Sender: TObject);
begin
if not TH_Eins.Terminated
then begin //Auf protected Symbol TThread.Terminated kann nicht zugegriffen werden
TH_Eins.Suspend;
end;
end;
procedure TForm1.Timer_Eins_ResumeClick(Sender: TObject);
begin
if not TH_Eins.Terminated
then begin //Auf protected Symbol TThread.Terminated kann nicht zugegriffen werden
TMyThreadUnit.TH_Eins.Resume;
end;
end;
procedure TForm1.Timer_Eins_StartClick(Sender: TObject);
begin
TH_Eins := TMyThread_Eins.Create(False);
end;
procedure TForm1.Timer_Eins_StopClick(Sender: TObject);
begin
TH_Eins.Terminate;
end;
procedure TForm1.Timer_Zwei_PauseClick(Sender: TObject);
begin
if not TH_Zwei.Terminated
then begin //Auf protected Symbol TThread.Terminated kann nicht zugegriffen werden
TH_Zwei.Suspend;
end;
end;
procedure TForm1.Timer_Zwei_ResumeClick(Sender: TObject);
begin
if not TH_Zwei.Terminated
then begin //Auf protected Symbol TThread.Terminated kann nicht zugegriffen werden
TH_Zwei.Resume;
end;
end;
procedure TForm1.Timer_Zwei_StartClick(Sender: TObject);
begin
TH_Zwei := TMyThread_Zwei.Create(False);
end;
procedure TForm1.Timer_Zwei_StopClick(Sender: TObject);
begin
TH_Zwei.Terminate;
end;
procedure TForm1.Write_Counter_Eins(Counter_Eins: integer);
begin
lbl_eins.Caption := IntToStr(Counter_Eins);
lbl_eins.Refresh;
end;
procedure TForm1.Write_Counter_Zwei(Counter_Zwei: integer);
begin
lbl_zwei.Caption := IntToStr(Counter_Zwei);
lbl_zwei.Refresh;
end;
procedure TForm1.Write_Uhr(Zeit: TTime);
begin
lbl_Zeit.Caption := TimeToStr(Zeit);
lbl_Zeit.Refresh;
end;
end.