WebPopupMenu

Hi,

A very small piece of code to demostrate may be a youth bug of th ie new TWebPopupMenu.
Open a new Web Core project and put a button on it, then put the following code which creates
at runtime a WebPopupMenu and add manually a few itemMenu all linked to the same onClick
event. It seems that the sender is always the first itemMenu and not the one that actually is
clicked. It works correctly if the webPopupMenu is created at design time.

Any suggestion ? Or is it a bug ?

Thanks

type
TForm4 = class(TWebForm)
WebPanel: TWebPanel;
WebButton: TWebButton;
procedure WebButtonClick(Sender: TObject);
procedure onItemClick(sender : TObject);

private
webPopMenu : TWebPopupMenu;

end;

var
Form4: TForm4;

implementation

{$R *.dfm}

procedure TForm4.WebButtonClick(Sender: TObject);
var
menuItem : TMenuItem;
begin
webPopMenu := TWebPopupMenu.create(webPanel);
webpopMenu.Parent := webPanel;

menuItem := TMenuItem.create(webPopMenu);
menuItem.caption := 'First Menu';
menuItem.onClick := onItemClick;
webPopMenu.items.add(menuItem);

menuItem := TMenuItem.create(webPopMenu);
menuItem.caption := 'Second Menu';
menuItem.onClick := onItemClick;
webPopMenu.items.add(menuItem);

menuItem := TMenuItem.create(webPopMenu);
menuItem.caption := 'Third Menu';
menuItem.onClick := onItemClick;
webPopMenu.items.add(menuItem);

webPopMenu.popup(50, 50);
end;

procedure TForm4.onItemClick(sender : TObject);
var
menuItem : TMenuItem;
begin
menuItem := TMenuItem(sender);
showMessage(menuItem.caption);
webPopMenu.free;
end;

end.

Hi,

Thank you for notifying.
This issue has now been fixed and the update will be available with the next release of TMS WEB Core.

As a workaround you can provide a valid Name value for each TMenuItem:

menuItem := TMenuItem.create(webPopMenu);
menuItem.caption := 'First Menu';
menuItem.Name := 'FirstMenu';
menuItem.onClick := onItemClick;
webPopMenu.items.add(menuItem);

menuItem := TMenuItem.create(webPopMenu);
menuItem.caption := 'Second Menu';
menuItem.Name := 'SecondMenu';
menuItem.onClick := onItemClick;
webPopMenu.items.add(menuItem);

menuItem := TMenuItem.create(webPopMenu);
menuItem.caption := 'Third Menu';
menuItem.Name := 'ThirdMenu';
menuItem.onClick := onItemClick;
webPopMenu.items.add(menuItem);