Is it possible to access the menu groups in code ?

Post

Posted
Rating:
#1 (In Topic #1275)
Regular
sergioabreu is in the usergroup ‘Regular’
 Just for curiosity.
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
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
Create a new project and add a new FMain

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.

Image

(Click to enlarge)


Now open up Form.class and add:

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Me.Center
  4.  
  5.  
  6. Public Sub Stop_Click()
  7.  
  8.  
  9.  

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!
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
 Controls/Menus do not have a Group property.
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
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
bill-lancaster is in the usergroup ‘Regular’
 This topic prompts me to ask for the best way to change an existing menu.tag value from code.

Any thoughts would be appreciated.
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
bill-lancaster is in the usergroup ‘Regular’
And another thing!
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
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’
 Please don't hijack other peoples posts with your own off-topic questions Bill
Online now: No Back to the top

Post

Posted
Rating:
#7
Regular
bill-lancaster is in the usergroup ‘Regular’
Sorry about that, it was your comment
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
that prompted it.  Won't do it again.
Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’

bill-lancaster said

Sorry about that, it was your comment
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
that prompted it.  Won't do it again.

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

Code (gambas)

  1.  
  2. Public Sub MyMenuGroup_Click()
  3.  
  4.   Dim hMenu As Menu = Last  ' get a pointer to the Menu object
  5.   Print hMenu.Tag
  6.   if hMenu.Tag = "stop" Then
  7.     Stop()
  8.   Else If hMenu.Tag = "start" Then
  9.     Start()
  10.  
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 Meanwhile, back at the original question…
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

Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
vuott is in the usergroup ‘Regular’
The creation of an "Event Group" refers to a sub-routine, and specifically to an Event that is referenced by two or more Objects.
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>
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’

vuott said

a single common Name to identify that Set of Objects that refer to that specific Event.
I think that best describes it. So, objects can have a common name that identifies them as a group

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!
Online now: No Back to the top

Post

Posted
Rating:
#12
Regular
vuott is in the usergroup ‘Regular’
...only a question of language structure.

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top
1 guest and 0 members have just viewed this.