[Lazarus] Add a MenuItem to a menu dynamically -> OnClick: wrong number parameters

Binho Biatheski rogerbip at gmail.com
Wed Mar 11 17:32:11 CET 2015


Hello,

Wrong number parameters specified for call to "MyPopup"

This example works in Delphi but not in Lazarus, what are parameters ?

procedure TForm1.Button1Click(Sender: TObject);
var
  MyItem,MySubItem1: TMenuItem;
  Num: Integer;
begin
  Inc(Num);
  MyItem:=TMenuItem.Create(Self);
  MySubItem1:=TMenuItem.Create(Self);

  MyItem.Caption:='Hello'+IntToStr(Num);
  MySubItem1.Caption:='Good Bye'+IntToStr(Num);

  MainMenu1.Items.Add(MyItem);
  MainMenu1.Items[0].Insert(num-1,MySubItem1);

  MyItem.OnClick:=MyPopUp;
  MySubItem1.OnClick:=MyPopUp;
end;

procedure TForm1.MyPopup(Sender: TObject);
begin
  with Sender as TMenuItem do ShowMessage(Caption);
end;


-- 
Binho
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150311/61cb8533/attachment-0002.html>


More information about the Lazarus mailing list