0
votes

I have this Lazarus program:

unit Unit2; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  StdCtrls, ComCtrls;

type

  { TForm2 }

  TForm2 = class(TForm)
    procedure OnTlacitkoClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    tlac:TButton;
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form2: TForm2;
 
implementation

{ TForm2 }

procedure TForm2.OnTlacitkoClick(Sender: TObject);
begin
  ShowMessage('helloworld');
end;

procedure TForm2.FormCreate(Sender: TObject);
var
  i, j: integer;
begin
  tlac := TButton.Create(Form2);
  tlac.OnClick := OnTlacitkoClick;
  tlac.Parent := Form2;
  tlac.Left := 100;
  tlac.Top := 100;
end;

initialization
  {$I unit2.lrs}

end.

But the compiler says the following error on the tlac.OnClick := OnTlacitkoClick; expression:

unit2.pas(63,32) Error: Wrong number of parameters specified for call to "OnTlacitkoClick"

I have searched, and think that this is a legal expression in Delphi. I want simply to register OnTlacitkoClick as tlac.OnClick event handler, not to call this procedure.

Is there something wrong with the code, or must I do it differently in Lazarus/FreePascal?

2

2 Answers

8
votes

As you already found out, add the @ or enable Delphi mode.

In (obj)fpc mode, the explicit @ is required to disambiguate some shady cases.

3
votes

Yes, I already have it! I must do Tlac.OnClick := @OnTlacitkoClick; instead of simply without @.