Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
- type
- { TForm1 }
- Tarray_of_tbutton = array of tbutton;
- TForm1 = class(TForm)
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- procedure MyArrayButtonsClick(Sender: TObject);
- procedure define_3x3_button_array;
- private
- { private declarations }
- public
- { public declarations }
- end;
- var
- Form1: TForm1;
- my_array_of_tbutton : Tarray_of_tbutton;
- implementation
- {$R *.lfm}
- procedure TForm1.MyArrayButtonsClick(Sender: TObject);
- begin
- Showmessage( 'You clicked on array button # ' +
- inttostr((Sender as Tbutton).Tag) );
- end;
- procedure TForm1.define_3x3_button_array;
- const
- max_horizontal = 3;
- max_vertical = 3;
- var
- v_count, h_count, array_count : integer;
- begin
- SetLength( my_array_of_tbutton, max_horizontal * max_vertical );
- for v_count := 0 to max_vertical - 1 do
- for h_count := 0 to max_horizontal - 1 do
- begin
- array_count := v_count * max_horizontal + h_count;
- my_array_of_tbutton[ array_count ] := new( tbutton( my_array_of_tbutton ));
- my_array_of_tbutton[ array_count ].Parent := Self;
- my_array_of_tbutton[ array_count ].Left :=
- 50 + h_count * 50;
- my_array_of_tbutton[ array_count ].Top :=
- 50 + v_count * 50;
- my_array_of_tbutton[ array_count ].Tag :=
- array_count;
- my_array_of_tbutton[ array_count ].OnClick :=
- myArrayButtonsClick;
- my_array_of_tbutton[ array_count ].Caption :=
- inttostr( array_count );
- end;
- end;
- procedure TForm1.myArrayButtonsClick( Sender : TObject );
- begin
- Showmessage( 'You clicked # ' + inttostr((Sender as TButton).Tag));
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- define_3x3_button_array;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement