Sub Menu.Close problem

I discovered a problem of one of my application under Windows. I don’t know if the problem is there for a long time or not as I don’t test (and use) my applications under Windows as much as under MacOS.
Please donwnload the sample problem
SubMenu.xojo_binary_project.zip (7.2 KB)
and run it. It simply creates submenu of menu File - Untitled . After the launch, there’s only one submenu “…”, click button “Make MenuA” and “Make MenuB” and “Make MenuC” some times in any order. → No problem.
Check the box CheckBox1 “Use Close (checked) or RemoveMenuAt (unchecked)” and problems will happen. The submenu are not removed. This problem appears only under Windows, not under MacOS.
Note: Label1 display the name of the submenu clicked, its index and the count of submenus.
Is it a bug or is it the way Menu.Close is supposed to work?

No need to use the others CheckBox 2 and 3, I added them to understand the different ways to manage submenu as explained in the doc and in the Xojo example project “Open Recent Menu”.

Have you tried just setting visible to false?

No, and I don’t think it will be usefull in my project. It is a memory game and the user can select a folder containing subfolders of CardsGame. Then he may select a folder with 8 cardsgame folder with their name, and then another folder containing 22 cardsgame with another name. And the way I do it (using RemoveMenuAt instead of Close works, but before submit a bug report I wanted to know if it is a bug. I think it is but I’m not sure.

Your code is confuse, uncommented, trying to pack several functionalities in one method alone like “closing or removing menus” in one function called “MakeSubMenu”.

That’s not a good design, hard to others to read and follow, and maybe works for the person who wrote it, but even that person can get confused with it in the future.

Try to separate your functionalities, as InsertGameIntoMenu(…) and RemoveGameFromMenu(…)
And when the remove function does not work it will be easier to see where and why it fails, sometimes it is just a dev logic fail he will catch when designing more specifically the functionalities.

If you still have problems after a redesign, remove all garbage from the sample, and post just the parts involved to avoid noise about the problem, like removing everything and having just one button with a ShowProblem()

Thank you for yours answers. I simplify my example project and I created an issue #78727 .
The result should be the same under MacOS and Windows.

Here is my approach based on what I’ve saw:

SubMenu_redesigned.zip (5.8 KB)

Even more simplified (just 2 menus) and better structured.

SubMenuItem.Close() is not updating LastRowIndex of the container when the item is removed using it.

Workaround fixing the problem:

Remove the MenuItem.Close()

Use RemoveMenuAt(index)

IF you did not close the sub MenuItem yet, it works, if you closed it, it will fail too later.

SubMenu_redesigned_2.zip (5.8 KB)