Assigning event handler during runtime results in compiler error lazarus / 8-Other ---------------------------------------------------------------------- tcare · 2010-01-20 20:48 I am dynamically creating a TBitBtn during runtime: NewPrintButton := TBitBtn.Create(paStatus); I declare the OnClick event: procedure NewPrintButtonClick(Sender: TObject); I set the properties: with NewPrintButton do          begin            Top := 5;            Width := buPrint.Width;            Height := buPrint.Height;            Left := 5;                   Glyph := buPrint.Glyph;            Parent := paStatus;           I ASSIGN ITS ONCLICK EVENT HANDLER HERE:            OnClick := NewPrintButtonClick;                    end; And write the handler here: procedure TfmMain.NewPrintButtonClick(Sender: TObject); begin   if Sender.ClassName = 'TBitBtn' then      ShowMessage(TBitBtn(Sender).Name + ' was clicked!'); end; However, when I try to compile, I get: Error: Wrong number of parameters specified for call to "NewPrintButtonClick" Am I missing something? ---------------------------------------------------------------------- Zoran · 2010-01-20 20:57 Unlike Delphi, in Free Pascal you must use @ operator in front of procedure variable. That means, instead of: OnClick := NewPrintButtonClick; You must write: OnClick := @NewPrintButtonClick; That's all. The error message about wrong number of paremeters is misleading. ---------------------------------------------------------------------- theo · 2010-01-20 21:22 Or set delphi compatibility mode: {$mode delphi} instead of {$mode objfpc} ---------------------------------------------------------------------- tcare · 2010-01-20 22:19 Thanks - I added the @ before the procedural variable and that did the trick! Theo - just out of curiosity, do you know if the {$mode delphi} directive affects performance in any way, or does it just allow you to use a more "Delphi-like" syntax?  Is there any additional performance hit translations occurring at runtime by using the {$mode delphi}? ---------------------------------------------------------------------- theo · 2010-01-20 22:59 Quote from: tcare on January 20, 2010, 11:19:25 pmdo you know if the {$mode delphi} directive affects performance in any way, or does it just allow you to use a more "Delphi-like" syntax? No, It does not affect performance afaik, it's a slightly less strict syntax than mode objfpc. http://www.freepascal.org/docs-html/prog/progap4.html#progse62.html