Retrieve MenuBar object from inside control event handler Topic is solved

Report problems with documented functionality
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Retrieve MenuBar object from inside control event handler

27 Apr 2018, 11:18

I am trying to gain access to the MenuBar object of a GUI which is the parent of a button control. I am probably doing something wrong or misread/missed something in the documentation.

Code: Select all

#SingleInstance Force

myMenu := MenuBarCreate()
myMenu.Add("Hello", (ItemName, ItemPos, Menu) => MsgBox(ItemPos))
myMenu.Add()
myMenu.Add("World", (ItemName, ItemPos, Menu) => MsgBox(ItemPos))

main := GuiCreate("", "My Gui Title")
main.menuBar := myMenu
; main.MarginX := 0, main.MarginY := 0
main.OnEvent("Close", () => ExitApp())
main.Add("Button", "w200", "Click Me!").OnEvent("Click", "clicked")
main.Show()

clicked(ctrlObj) {
    MsgBox(ctrlObj.Gui.Title)
    MsgBox(IsObject(ctrlObj.Gui.MenuBar)) ; 0 when I would expect it to show 1
}
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: Retrieve MenuBar object from inside control event handler

27 Apr 2018, 11:57

it seems like a bug...

Code: Select all

; from https://lexikos.github.io/v2/docs/objects/Gui.htm#MenuBar
FileMenu := MenuCreate()
FileMenu.Add "&Open`tCtrl+O", () => FileSelect()  ; See remarks below about Ctrl+O.
FileMenu.Add "E&xit", () => ExitApp()
HelpMenu := MenuCreate()
HelpMenu.Add "&About", () => MsgBox("Not implemented")
Menus := MenuBarCreate()
Menus.Add "&File", FileMenu  ; Attach the two submenus that were created above.
Menus.Add "&Help", HelpMenu
Gui := GuiCreate()
Gui.MenuBar := Menus
Gui.Show "w300 h200"

MsgBox Gui.MenuBar . "|" . Type(Gui.MenuBar) . "|" . IsObject(Gui.MenuBar)
ExitApp
Edit: Maybe the problem is here:

Code: Select all

		case P_MenuBar:
		{
			if (IS_INVOKE_SET)
			{
				ResultType result = SetMenu(*aParam[0]);
				if (result != OK)
					return result; // Already displayed error.
			}
			_o_return_empty; // TODO
		}
It seems like not implemented. :shock:
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Retrieve MenuBar object from inside control event handler  Topic is solved

04 May 2018, 21:38

I forgot to post here after releasing v2.0-a095 to let you know it's fixed, and it was also missing from the announcement topic. The fix was actually the first change after v2.0-a094.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Retrieve MenuBar object from inside control event handler

07 May 2018, 07:12

Awesome, thanks! Apologies for not specifying which version I was using at the time of the OP. Will make sure I include that for any future posts.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 23 guests