Menu - Remove

XOJO 2022r1 - Windows 10
After converting to API2 and a few days of work, almost all of the 8611 errors are solved, except one ;;
Code below ;

Var mnu1 As DesktopMenuItem = mnuFrmMixMaster.Child(Instrument)
mnuFrmMixMaster.Remove(mnu1)

Line ‘mnuFrmMixMaster.Remove(mnu1)’ gives an error
mnuFrmMixMaster.mnuFrmMixMaster has no member named ‘Remove’

Thanks
Regards
Etienne

Try RemoveMenuAt

MenuItem.Remove
Removes the MenuItem specified by its index .

DesktopMenuItem.RemoveMenuAt
Removes the DesktopMenuItem specified by its position (index).

Thanks.
I already tried but that doesn’t work.
Another error shows up saying ;
Parameter “index” expects type integer, but this is class DesktopMenuItem.

‘mnu1’ is a menu in the menubar mnuFrmMixMaster

In XOJO 2021r1.1 There are 2 possibilities ;
MenuItem.Remove(Index As Integer) → Removes the MenuItem specified by its index.
MenuItem.Remove(Item As MenuItem) → removes the menu specified by reference.
For the code in bold I am looking for a replacement in XOJO 2022r1.

Regards
Etienne

i believe you need replace the argument
MenuItem to DesktopMenuItem

@MarkusR
That is just my problem : after changing to DesktopMenuItem Remove by reference is no more available ???.
I’m looking for a way to solve this…

Regards

You Can’t mix DesktopMenus and MenuItems or vice versa. You can only add DesktopMenuItems to a DesktopMenu. You can only add MenuItems to a Menu. All the classes either have to be Desktop or Not.

I don’t think I mix MenuItems and DesktopMenuItems.

Var mnu1 As DesktopMenuItem = mnuFrmMixMaster.Child(Instrument)
mnuFrmMixMaster.Remove(mnu1)

mnu1 is a DesktopMenuItem

mnuFrmMixMaster (MenuBar) I suppose is been converted to Desktop too with the ‘Update controls to API2’ action.

Regards

@Volbragt_Etienne

Just loop through the children of the parent menu to find the index and then use it with RemoveMenuAt. That’s what would have been done under the hood anyway.

seems this method was not converted to api 2
https://documentation.xojo.com/api/user_interface/desktop/desktopmenubar.html
old one
https://documentation.xojo.com/api/deprecated/menubar.html#menubar

there is a AddMenu with object but not the opposite.
i would expext a RemoveMenu method.

You can also possibly find the menu item, using ParentMenu.Child and call its “close” method. I haven’t tried in this context, but you can give it a try.

@Arnaud_N Didn’t work with close.

I found a solution ;
As it are 2 menus that are dynamically created when running, they are placed at the end of the menubar (two last indexes).
So I do twice a 'menuBar.RemoveMenuAt(menuBar.LastRowIndex)
This does exactly what i wanted.

However I will later on search for a better solution.
Or perhaps XOJO will create a Remove menu by reference as existed before API2.

Thanks for all your replies.

Regards
Etienne