Lazarus - why I can't assign event to run-time component?

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 compiler says: unit2.pas(63,32) Error: Wrong number of parameters specified for call to "OnTlacitkoClick" in tlac.OnClick:=OnTlacitkoClick; expression. I have searched and think that this is legal expression in Delphi. I want simply to registrate OnTlacitkoClick as tlac.OnClick event,not to call this procedure. Is there somethink wrong with the code or must I do it different in Lazarus/Freepascal?

Thanks.

Answers


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

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


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


Need Your Help

Unable to delete a file in Windows using javascript in node.js

javascript node.js

I have the following code which tries to delete a file on a windows 7 machine: