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

Kadaitcha Man nospam.nospam.nospam at ...176...
Thu Dec 31 03:00:24 CET 2009


2009/12/31 Benoît Minisini <gambas at ...1...>:
>> 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.

Really? I could have sworn you indicated that very thing for someone
else's issue. OK, I'll take your word for it and will try it.

>> 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".

That would solve a lot of problems.

>> 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.

YES! That's it. And CRIPES! I may need a new brain. Or there's a
problem in the doc somewhere. When I was researching this I didn't see
Action documented as being available for Menus. However I just went
back and sure enough, there it is.

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

I will get to testing it. And I will apologise to the OP as well. Thank you.




More information about the Devel mailing list