Page 1 of 1

a104: Re: [a104] Unknown method error A_TrayMenu.Delete()

Posted: 18 Aug 2019, 08:48
by Maestr0
I posted a question here: https://www.autohotkey.com/boards/viewtopic.php?f=82&t=67201
and also asked in v2 on Discord.

It seems there is currently no way to delete the standard tray menu items.

Cap'n'Odin thinks it might be due to this: https://github.com/Lexikos/AutoHotkey_L/commit/0c9151f25bc32f998ec0514053151034d80b6c2b

Why does this code throw an "Unknown method" error with a104?
It's example #3 from "tray menu (customizing)"

Code: Select all

global tray := A_TrayMenu ; For convenience.
tray.delete ; Delete the standard items.
tray.Add("reload", "reload")
Error: Unknown method.

Specifically: delete

Line#
001: tray := A_TrayMenu
---> 002: tray.delete()
003: tray.Add("reload", "reload")

Re: a104: Re: [a104] Unknown method error A_TrayMenu.Delete()

Posted: 18 Aug 2019, 09:12
by Maestr0
It seems to be limited to the tray menu, as the code below seems to work just fine (only shows "reload 3"):

Code: Select all

MyMenu := MenuCreate()
MyMenu.Add("reload 1", "reload")
MyMenu.Delete()
MyMenu.Add("reload 3", "reload")

#z::MyMenu.Show  ; i.e. press the Win-Z hotkey to show the menu.

Re: a104: Re: [a104] Unknown method error A_TrayMenu.Delete()

Posted: 18 Aug 2019, 11:38
by joefiesta
i don't get any such error. I run 1.1.30.01 AHK under Win 7 Pro 32 bit. But, for what it is worth, it also does not clear the tray menu (even after adding a (necessary?) #persistent to the code).

What are you running?

Re: a104: Re: [a104] Unknown method error A_TrayMenu.Delete()

Posted: 18 Aug 2019, 12:27
by Maestr0
joefiesta wrote:
18 Aug 2019, 11:38
i don't get any such error. I run 1.1.30.01 AHK under Win 7 Pro 32 bit. But, for what it is worth, it also does not clear the tray menu (even after adding a (necessary?) #persistent to the code).

What are you running?
Hey Joe, thank you for pitching in. Sorry I was unclear, this is a v2 bug report, version a104.

No, #persistent is not necessary in this case.

Oh, and 1.1.30.03 was released as well :)

Re: a104: Re: [a104] Unknown method error A_TrayMenu.Delete()

Posted: 19 Aug 2019, 03:10
by lexikos
Long story short, the tray menu is created before the Menu object prototype, so the Tray menu has no base object and therefore no predefined methods or properties.

This can be used to "fix" the tray menu (v2.0-a104 only):

Code: Select all

Menu_Prototype := MenuCreate().base
ObjAddRef(&Menu_Prototype)
NumPut("ptr", &Menu_Prototype, &A_TrayMenu + 8 + A_PtrSize)

v1.1.30.03 was released over 4 months ago.

Re: a104: Re: [a104] Unknown method error A_TrayMenu.Delete()

Posted: 19 Aug 2019, 04:23
by Maestr0
lexikos wrote:
19 Aug 2019, 03:10
Long story short, the tray menu is created before the Menu object prototype, so the Tray menu has no base object and therefore no predefined methods or properties.

This can be used to "fix" the tray menu (v2.0-a104 only):

Code: Select all

Menu_Prototype := MenuCreate().base
ObjAddRef(&Menu_Prototype)
NumPut("ptr", &Menu_Prototype, &A_TrayMenu + 8 + A_PtrSize)
Thanks, that fixed it.

Re: a104: Re: [a104] Unknown method error A_TrayMenu.Delete()  Topic is solved

Posted: 24 Sep 2019, 02:25
by lexikos
Fixed in v2.0-a105.

Re: a104: Re: [a104] Unknown method error A_TrayMenu.Delete()

Posted: 28 Sep 2019, 06:24
by Maestr0
lexikos wrote:
24 Sep 2019, 02:25
Fixed in v2.0-a105.
awesome, thanks for the update.

Re: a104: Re: [a104] Unknown method error A_TrayMenu.Delete()

Posted: 28 Sep 2019, 18:24
by lexikos
This bug-fix introduced a new bug, which can be worked around as follows:

Code: Select all

if !ObjGetBase(A_TrayMenu.base)
	ObjSetBase(A_TrayMenu.base, Object.Prototype)