[Lazarus] compile errors trying to create array of tbutton.

Mattias Gaertner nc-gaertnma at netcologne.de
Sat May 21 18:46:50 CEST 2011


On Sun, 22 May 2011 01:37:35 +1000
Peter Williams <peterericwilliams at gmail.com> wrote:

> type
>   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;
> 
> 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 ] := TButton.Create(Self);


>        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;

You forgot the address operator:
          @myArrayButtonsClick;

> unit1.pas(61,29) Error: Wrong number of parameters specified for call
> to "MyArrayButtonsClick"
> unit1.pas(34,18) Hint: Found declaration: TForm1.MyArrayButtonsClick(TObject);
> unit1.pas(67,18) Error: overloaded functions have the same parameter list
> unit1.pas(34,18) Hint: Found declaration: TForm1.MyArrayButtonsClick(TObject);
> unit1.pas(67,18) Error: function header doesn't match any method of
> this class "TForm1.MyArrayButtonsClick(TObject);"
> unit1.pas(34,18) Hint: Found declaration: TForm1.MyArrayButtonsClick(TObject);
> unit1.pas(79) Fatal: There were 4 errors compiling module, stopping


Mattias




More information about the Lazarus mailing list