Advertisement
petethepoet

array of tbuttons unit - with some compile errors (2)

May 21st, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.89 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   Tarray_of_tbutton = array of tbutton;
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     procedure Button1Click(Sender: TObject);
  18.     procedure MyArrayButtonsClick(Sender: TObject);
  19.     procedure define_3x3_button_array;
  20.   private
  21.     { private declarations }
  22.   public
  23.     { public declarations }
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.   my_array_of_tbutton : Tarray_of_tbutton;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. procedure TForm1.MyArrayButtonsClick(Sender: TObject);
  35. begin
  36.   Showmessage( 'You clicked on array button # ' +
  37.     inttostr((Sender as Tbutton).Tag) );
  38. end;
  39.  
  40. procedure TForm1.define_3x3_button_array;
  41. const
  42.   max_horizontal = 3;
  43.   max_vertical = 3;
  44. var
  45.   v_count, h_count, array_count : integer;
  46. begin
  47.   SetLength( my_array_of_tbutton, max_horizontal * max_vertical );
  48.   for v_count := 0 to max_vertical - 1 do
  49.    for h_count := 0 to max_horizontal - 1 do
  50.      begin
  51.        array_count := v_count * max_horizontal + h_count;
  52.        my_array_of_tbutton[ array_count ] := new( tbutton( my_array_of_tbutton ));
  53.        my_array_of_tbutton[ array_count ].Parent := Self;
  54.        my_array_of_tbutton[ array_count ].Left :=
  55.          50 + h_count * 50;
  56.        my_array_of_tbutton[ array_count ].Top :=
  57.          50 + v_count * 50;
  58.        my_array_of_tbutton[ array_count ].Tag :=
  59.          array_count;
  60.        my_array_of_tbutton[ array_count ].OnClick :=
  61.          myArrayButtonsClick;
  62.        my_array_of_tbutton[ array_count ].Caption :=
  63.          inttostr( array_count );
  64.      end;
  65. end;
  66.  
  67. procedure TForm1.myArrayButtonsClick( Sender : TObject );
  68. begin
  69.   Showmessage( 'You clicked # ' + inttostr((Sender as TButton).Tag));
  70. end;
  71.  
  72. procedure TForm1.Button1Click(Sender: TObject);
  73. begin
  74.   define_3x3_button_array;
  75. end;
  76.  
  77. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement