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
TfrmMain =
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;
pnl_MultiThreads: TPanel;
pnl_MainThread: TPanel;
pnl_Results: TPanel;
procedure btn_einsClick(Sender: TObject);
procedure btn_zweiClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer_Eins_StartClick(Sender: TObject);
procedure Timer_Eins_PauseClick(Sender: TObject);
procedure Timer_Eins_ResumeClick(Sender: TObject);
procedure Timer_Eins_StopClick(Sender: TObject);
procedure Timer_Zwei_StartClick(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 FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
MyThread: TMyThreads;
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
frmMain: TfrmMain;
implementation
{$R *.dfm}
//Alles im MainThread
procedure TfrmMain.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 TfrmMain.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 TfrmMain.Timer1Timer(Sender: TObject);
begin
//lbl_Zeit.Caption := TimeToStr(now());
end;
//OnCreate, OnShow, OnDestroy Proceduren
procedure TfrmMain.FormCreate(Sender: TObject);
begin
MyThread := TMyThreads.Create;
end;
procedure TfrmMain.FormShow(Sender: TObject);
begin
MyThread.TH_Uhr_Start(True);
MyThread.TH_Uhr.WriteClockValue := Write_Uhr;
MyThread.TH_Uhr.Resume;
end;
procedure TfrmMain.FormDestroy(Sender: TObject);
begin
MyThread.TH_Uhr_Stop;
MyThread.TH_Eins_Stop;
MyThread.TH_Zwei_Stop;
MyThread.Free;
end;
//ClickProceduren
//Im MainThread
procedure TfrmMain.btn_einsClick(Sender: TObject);
begin
Timer_Eins;
end;
procedure TfrmMain.btn_zweiClick(Sender: TObject);
begin
Timer_Zwei;
end;
procedure TfrmMain.btn_EinsZweiClick(Sender: TObject);
begin
MyThread.TH_Eins_Start(true);
MyThread.TH_Eins.WriteTHEinsValue := Write_Counter_Eins;
MyThread.TH_Eins.Resume;
MyThread.TH_Zwei_Start(true);
MyThread.TH_Zwei.WriteTHZweiValue := Write_Counter_Zwei;
MyThread.TH_Zwei.Resume;
end;
//MultiThreads
//TH_Eins Ckick
procedure TfrmMain.Timer_Eins_StartClick(Sender: TObject);
begin
MyThread.TH_Eins_Start(true);
MyThread.TH_Eins.WriteTHEinsValue := Write_Counter_Eins;
MyThread.TH_Eins.Resume;
end;
procedure TfrmMain.Timer_Eins_PauseClick(Sender: TObject);
begin
MyThread.TH_Eins_Break;
end;
procedure TfrmMain.Timer_Eins_ResumeClick(Sender: TObject);
begin
MyThread.TH_Eins_Resume;
end;
procedure TfrmMain.Timer_Eins_StopClick(Sender: TObject);
begin
MyThread.TH_Eins_Stop;
end;
//TH_Zwei Click
procedure TfrmMain.Timer_Zwei_StartClick(Sender: TObject);
begin
MyThread.TH_Zwei_Start(true);
MyThread.TH_Zwei.WriteTHZweiValue := Write_Counter_Zwei;
MyThread.TH_Zwei.Resume;
end;
procedure TfrmMain.Timer_Zwei_PauseClick(Sender: TObject);
begin
MyThread.TH_Zwei_Break;
end;
procedure TfrmMain.Timer_Zwei_ResumeClick(Sender: TObject);
begin
MyThread.TH_Zwei_Resume;
end;
procedure TfrmMain.Timer_Zwei_StopClick(Sender: TObject);
begin
MyThread.TH_Zwei_Stop;
end;
//Schreibproceduren
procedure TfrmMain.Write_Counter_Eins(Counter_Eins: integer);
begin
lbl_eins.Caption := IntToStr(Counter_Eins);
lbl_eins.Refresh;
end;
procedure TfrmMain.Write_Counter_Zwei(Counter_Zwei: integer);
begin
lbl_zwei.Caption := IntToStr(Counter_Zwei);
lbl_zwei.Refresh;
end;
procedure TfrmMain.Write_Uhr(Zeit: TTime);
begin
lbl_Zeit.Caption := TimeToStr(Zeit);
lbl_Zeit.Refresh;
end;
end.