unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure HangKlick(Sender: TObject);
public
{ Public declarations }
end;
type
THangManWordInterface =
class
private
public
Buttons:
array[0..25]
of TButton;
constructor Create(top,left:integer; owner: TComponent);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor THangManWordInterface.Create(top,left: integer; owner: TComponent);
var i:integer; abc:
string;
begin
abc:='
ABCDEFGHIJKLMNOPQRSTUVWXYZ';
for i:=0
to 25
do begin
Buttons[i]:=TButton.Create(owner);
Buttons[i].Parent:=TWincontrol(owner);
Buttons[i].left:=i*20+left;
Buttons[i].Top:=top;
Buttons[i].Width:=20;
Buttons[i].Height:=20;
Buttons[i].Caption:=abc[i+1];
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
HangMan: THangManWordInterface;
i : integer;
begin
HangMan:= THangManWordInterface.Create(10, 10, self);
for i:= low(HangMan.Buttons)
to high(HangMan.Buttons)
do
HangMan.Buttons[i].OnClick:= HangKlick;
end;
procedure TForm1.HangKlick(Sender: TObject);
begin
if Sender
is TButton
then
Caption:= TButton(Sender).Caption
end;
end.