Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-05

compile errors trying to create array of tbutton.

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Peter Williams
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 ].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;

Full code is here: http://pastebin.com/ueKmjkrC

Options changed, recompiling clean with -B
Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.5.1 [2011/05/14] for i386 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Linux for i386
Compiling slide_puzzle.lpr
Compiling unit1.pas
unit1.pas(52,81) Error: Type identifier expected
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

Best Regards,
Peter

Reply by email

Mattias Gaertner
to Peter Williams
Show quoted text 31 lines
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);
Show quoted text 9 lines
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;
Show quoted text 9 lines
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

Reply by email

Peter Williams
to Mattias Gaertner

Hi Mattias,

Mattias Gaertner wrote
On Sun, 22 May 2011 01:37:35 +1000 Peter Williams wrote:

[...]

Show quoted text 7 lines
> ? ? ? ?my_array_of_tbutton[ array_count ].OnClick := > ? ? ? ? ?myArrayButtonsClick; You forgot the address operator: ? ? ? ? ;

Thanks for the help, Mattias. :-)

Show quoted text 8 lines
Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email