Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-03

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

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Binho Biatheski

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.freepascal.org/pipermail/lazarus/attachments/20150311/61cb8533/attachment.html>

Reply by email

Binho Biatheski
to Felipe Monteiro de Carvalho

Thank you !!!

2015-03-11 13:39 GMT-03:00 Felipe Monteiro de Carvalho <

Show quoted text 17 lines
: Add @ to procedure names: ; ; -- Felipe Monteiro de Carvalho -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Binho http://www.biatheski.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150311/9d3bbf0b/attachment.html>

Reply by email

Graeme Geldenhuys
to Felipe Monteiro de Carvalho: Add @ to procedure names: ; ; Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote
; ;

More specifically... it depends of the compiler mode. Is the source code shared between Lazarus and Delphi? If so you probably want to use the delphi mode at the top of the unit. Then no @ prefix is required.

  {$mode delphi}

If the code is Lazarus only, then you probably want the objfpc mode - at which point you need to add the @ prefix to the event handler as quoted above.

  {$mode objfpc}

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email