Is it possible to access the menu groups in code ?
Posted
#1
(In Topic #1275)
Regular

How do I access the "Group" that menus have ?
Shouldn't it be an available and programmable property of the menu or its children ?
Thanks
Posted
Administrator

From menu editor add Menu1, Menu2 and Menu3.
Indent Menu 2 and Menu3
Menu1 name = Data
Menu2 name = Cancel
Menu3 name = Quit
Put Menu2 and Menu3 in group Stop (just write Stop first time in first menu and select Stop from dropdown box for the second menu).
Result is shown in screenshot below.
Now open up Form.class and add:
Next run the application and see what happens if you click menu Cancel and menu Quit.
This should explain what you asked.
If not…ask..
Note: Group makes it possible to group events, meaning Controls with the same events can share code by grouping them.
I use Tag a lot (combined with groups) to determine what control in the group was clicked.
Combine groups and tags with collections and you got raw power…
Edit: Menu's are probably not the most common place to use groups
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Guru

a "Group" is just something handled by the IDE only and is a way to allow objects to share an event name.
So you are essentially asking is it possible to access the Event name of an object. and that's a no,it is not possible.
The Action property might be a better thing to use to access groups of objects.
Or using .Tag to set some identifiers for the menus
Posted
Regular

Any thoughts would be appreciated.
Posted
Regular

This code creates a new menu but its not permanent, it only exists during the instance of the form.
Code
Dim hMenu As Menu
With hMenu = New Menu(Menu1)
.Text = "trial menu"
.Name = "MenuXXX"
.Tag = "XXX"
.Caption = "CAPTION"
.Visible = True
.Enabled = True
End With
Posted
Guru

Posted
Regular

that prompted it. Won't do it again.The Action property might be a better thing to use to access groups of objects.
Or using .Tag to set some identifiers for the menus
Posted
Guru

bill-lancaster said
Sorry about that, it was your commentthat prompted it. Won't do it again.The Action property might be a better thing to use to access groups of objects.
Or using .Tag to set some identifiers for the menus
No worries, thank you .
but to answer what i meant as using .Tag as an identifier….
the .Tag is a Variant (so it can be anything) that can be accessed any time by code, all you need it the pointer to the menu.
In your above code example the hMenu object is local to the function so will not be available anywhere else but the menu is created and stays created.
You can either use a Global hMenu that you can access anywhere or you can use the Last keyword in the menu's event to access the Menu object.
I often use the .Tag to identify what menu has been clicked from a group as I assume translations of the program could happen so the .Caption cannot be relied on (I usually use the .Name but sometimes .Name is not set).
Posted
Regular

Do "objects" have "groups" or conversely do "groups" have "objects"?
This has only been addressed in an abstract sense by BruceS.
What exactly is a "group"?
Interesting.
b
Posted
Regular

The purpose of assigning multiple Objects to a single "Event Group" is to adopt a shortcut to use a single common Name to identify that Set of Objects that refer to that specific Event.
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Administrator

I think that best describes it. So, objects can have a common name that identifies them as a groupvuott said
a single common Name to identify that Set of Objects that refer to that specific Event.
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Regular

Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
1 guest and 0 members have just viewed this.


