UNIT uMain;
INTERFACE
USES
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Vcl.ExtCtrls;
TYPE
TOnChangeEvent =
PROCEDURE( Sender: TObject; MaxValue: Integer; CurrentValue: Integer )
OF OBJECT;
{ mein Event-Hanlder für den 2. Thread }
Tfrm_Main =
CLASS( TForm )
Btn_Start_Thread1: TButton;
CounterLabel1: TLabel;
Btn_End_Thread1: TButton;
Label1: TLabel;
Bevel1: TBevel;
Btn_Start_Thread2: TButton;
Btn_End_Thread2: TButton;
Counterlabel2: TLabel;
PROCEDURE FormClose( Sender: TObject;
VAR Action: TCloseAction );
PROCEDURE Btn_Start_Thread1Click( Sender: TObject );
PROCEDURE Btn_End_Thread1Click( Sender: TObject );
PROCEDURE DoOnChange( Sender: TObject; MaxValue: Integer; CurrentValue: Integer );
PROCEDURE Btn_Start_Thread2Click( Sender: TObject );
PROCEDURE Btn_End_Thread2Click( Sender: TObject );
PROCEDURE FormCreate( Sender: TObject );
PRIVATE
{ Private-Deklarationen }
PUBLIC
{ Public-Deklarationen }
VAR
gb_ist_Thread1_aktiv, gb_ist_Thread2_aktiv: Boolean;
END;
VAR
frm_Main: Tfrm_Main;
IMPLEMENTATION
{$R *.dfm}
USES
uThread_mit_Erzeugung_Controls_fuer_Zugriff_auf_VCL_im_Hauptthread, uThread_mit_Businesslogic_kennt_somit_nicht_den_HauptThread;
{ mein Event-Handler von dem 2. Thread }
PROCEDURE Tfrm_Main.DoOnChange( Sender: TObject; MaxValue: Integer; CurrentValue: Integer );
BEGIN
frm_Main.CounterLabel2.Caption := CurrentValue.ToString;
END;
PROCEDURE Tfrm_Main.FormCreate( Sender: TObject );
BEGIN
gb_ist_Thread1_aktiv := False;
gb_ist_Thread2_aktiv := False;
END;
PROCEDURE Tfrm_Main.Btn_Start_Thread1Click( Sender: TObject );
BEGIN
Btn_Start_Thread1.Enabled := False;
Btn_Start_Thread2.Enabled := False;
Btn_End_Thread2.Enabled := False;
FMy_Thread1 := TTheThread.Create( CounterLabel1 );
END;
PROCEDURE Tfrm_Main.Btn_End_Thread1Click( Sender: TObject );
BEGIN
IF frm_Main.gb_ist_Thread1_aktiv
THEN FMy_Thread1.Terminate;
Btn_Start_Thread1.Enabled := True;
Btn_End_Thread1.Enabled := True;
Btn_Start_Thread2.Enabled := True;
Btn_End_Thread2.Enabled := True;
END;
PROCEDURE Tfrm_Main.Btn_Start_Thread2Click( Sender: TObject );
BEGIN
Btn_Start_Thread1.Enabled := False;
Btn_End_Thread1.Enabled := False;
Btn_Start_Thread2.Enabled := False;
FMy_Thread2 := TTheThread2.Create;
FMy_Thread2.OnChange := DoOnChange;
{ ! }
END;
PROCEDURE Tfrm_Main.Btn_End_Thread2Click( Sender: TObject );
BEGIN
IF frm_Main.gb_ist_Thread2_aktiv
THEN FMy_Thread2.Terminate;
Btn_Start_Thread1.Enabled := True;
Btn_End_Thread1.Enabled := True;
Btn_Start_Thread2.Enabled := True;
Btn_End_Thread2.Enabled := True;
END;
PROCEDURE Tfrm_Main.FormClose( Sender: TObject;
VAR Action: TCloseAction );
BEGIN
IF frm_Main.gb_ist_Thread1_aktiv
THEN FMy_Thread1.Terminate;
IF frm_Main.gb_ist_Thread2_aktiv
THEN FMy_Thread2.Terminate;
END;
END.