Recent

Author Topic: OnClick procedure for Control Arrays.  (Read 7798 times)

Hopestation

  • Full Member
  • ***
  • Posts: 181
OnClick procedure for Control Arrays.
« on: October 08, 2010, 11:49:44 am »
Hello.

In Delphi4 I can create an array of radio buttons and use a common OnClickRdBtn call.

Here is my Delphi code:-

uses
..
    procedure RdBtnClick(Sender: TObject);
..
implementation
..
procedure TForm1.FormCreate(Sender: TObject);
Var
  N: Integer;
begin
  For N := 0 to 9 Do
  begin
    RdBtn[N] := TRadioButton.Create(Owner);
    RdBtn[N].Parent := RadioGroup1;
    RdBtn[N].OnClick := RadioButtonClick;
  end;
..
   procedure TForm1.RdBtnClick(Sender: TObject);
Var
  Source: TRadioButton;
  N: Integer;
begin
  Source := TRadioButton(Sender);
  N := Source.Tag;
  Edit1.Text := IntToStr(N);;
end;

This works and operates on the selected button.

When I import it into Lazarus it still works.

When I try to create the form in Lazarus I get the message not enough paramerters, but nothing to tell me what parameters are required.

Here is my Lazarus code:-

uses
..
    procedure RadioButtonClick(Sender: TObject);
..
implementation
..
procedure TForm1.FormCreate(Sender: TObject);
Var
  N: Integer;
begin
  For N := 0 to 9 Do
  begin
    RdBtn[N] := TRadioButton.Create(Owner);
    RdBtn[N].Parent := RadioGroup1;
    RdBtn[N].OnClick := RadioButtonClick;
  end;
end;
..
procedure TForm1.RadioButtonClick(TRadioButton);
Var
  Source: TRadioButton;
begin
  Frm_Main_1.Edit3.Text := Copy(RadioButton9.Caption,1,1);
end; 

The following messages are displayed:-
type1.pas(58,41) Error: Wrong number of parameters specified for call to "RadioButtonClick"
type1.pas(18,15) Hint: Found declaration: TForm1.RadioButtonClick(TObject);
type1.pas(62,47) Fatal: Syntax error, ":" expected but ")" found.

What am I doing wrong?

Thanks
Roger.

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: OnClick procedure for Control Arrays.
« Reply #1 on: October 08, 2010, 11:54:20 am »
as you defined the method:
procedure TForm1.RadioButtonClick(TRadioButton);

you should add this in the type:

procedure RadioButtonClick(TRadioButton);


OR

you can try
procedure RadioButtonClick(TRadioButton); instead of TForm1.
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: OnClick procedure for Control Arrays.
« Reply #2 on: October 08, 2010, 12:02:37 pm »
Also, try this:

Code: [Select]
RdBtn[N].OnClick := @RdBtnClick;
Note the @-symbol.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

Hopestation

  • Full Member
  • ***
  • Posts: 181
Re: OnClick procedure for Control Arrays.
« Reply #3 on: October 09, 2010, 03:08:50 pm »
Thank you both for your help.

Using @ worked. I don't need this in Delphi4.

Is there a simple explanation of why it is needed in Lazarus?

Regards

Roger

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: OnClick procedure for Control Arrays.
« Reply #4 on: October 09, 2010, 03:17:11 pm »
Free Pascal support various Pascal dialects. If you want to use the Delphi dialect then you should use the {$mode delphi} directive in your source code.

 

TinyPortal © 2005-2018