[Gambas-devel] gb3 menus and the item that was clicked

Benoît Minisini gambas at ...1...
Thu Dec 31 02:34:43 CET 2009


> 2009/12/31 Toni <arosa at ...615...>:
> > Hi,
> > Did you try using "LAST" ?
> >
> > E.g. Last.Name would give you the name of the last clicked menu.
> >
> > For instance, if you generate the menus dinamically  I guess that you
> > could use the same event firing for all of them (I haven't  tested it,
> > but it could go as follows):
> >
> >  DIM mnu AS Menu
> >  mnu = NEW Menu(rootmenu) AS "MnuHandler"
> >  mnu.Name = "mnu1"
> >  mnu.Caption = "a"
> >  mnu = NEW Menu(rootmenu) AS "MnuHandler"
> >  mnu.Name = "mnu2"
> >  mnu.Caption = "b"
> >
> > and then
> >
> > PUBLIC SUB MnuHandler_Click()
> >    DEBUG Last.Name
> > END
> 
> It won't work.
> 
> 1) The second mnu = NEW Menu(rootmenu) AS "MnuHandler" will kill the
> event handler of the first instance.
> 

No, why? The two menus are just two differents objects that point at the same 
event handler.

> 2) MnuHandler_Click is the event handler for the parent only.

No, MnuHandler_Click is the event handler of any control whose event name is 
"MnuHandler".

> 
> 3) I will need thousands of lines of additional code if I have to
> construct the menu dynamically. I could load an array from data and
> loop through it, but it's a moot idea because of points 1) and 2).
> 

If your entries are defined in the IDE, you must assign each of them to the 
same group, so that clicking on any menu will raise the same event handler.

Then, in the event handler, you use LAST to know which menu item was clicked.

Regards,

-- 
Benoît Minisini




More information about the Devel mailing list