unit Test_Unit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 =
class(TForm)
Btn_1: TButton;
Btn_2: TButton;
Btn_3: TButton;
Btn_4: TButton;
procedure FormCreate(Sender: TObject);
procedure Btn_1Click(Sender: TObject);
procedure Btn_2Click(Sender: TObject);
procedure Btn_3Click(Sender: TObject);
procedure Btn_4Click(Sender: TObject);
private
{ Private-Deklarationen }
BtnNumber: Integer;
procedure onButtonClick(Sender: TButton);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
BtnNumber := Random(3);
end;
procedure TForm1.onButtonClick(Sender: TButton);
begin
if Sender.Tag = BtnNumber
then
ShowMessage('
Du hast den richtigen Button erwischt!');
end;
procedure TForm1.Btn_1Click(Sender: TObject);
begin
onButtonClick(Btn_1);
end;
procedure TForm1.Btn_2Click(Sender: TObject);
begin
onButtonClick(Btn_2);
end;
procedure TForm1.Btn_3Click(Sender: TObject);
begin
onButtonClick(Btn_3);
end;
procedure TForm1.Btn_4Click(Sender: TObject);
begin
onButtonClick(Btn_4);
end;
end.