Window.EnableMenuItems not firing

My app creates windows on the fly. ImplicitInstance is off, the App object has the window assigned to it, with its menubar also assigned. The first window created works correctly. In all newly created windows after that, Window.EnableMenuItems() never fires, and no menu handlers fire. The menubar is visible and assigned to the window. Clicking the menubar brings up the correct options. Using key shortcuts appears to select the correct menu item (it’s highlighted when the shortcut is used), but menu handlers don’t fire. Putting a simple beep in the Window.EnableMenuItems() event shows that it never fires in these “dead” windows. It does fire in the first working window. Anyone know what would cause this?

Xojo has an example called XojoText. Is this working for you? Are you doing something similar?

Yes and yes.

I shouldn’t really call the windows “dead” because they work otherwise. Toolbar works, functions within the window work. All menu handlers which are handled by the App object also work. What doesn’t work are all the menus handled by the window. I can force the Window.EnableMenuItems() event to fire by calling App.RefreshMenuBar, but that doesn’t fix the problem. The event is supposed to fire when menu items are clicked or shortcuts are used, and that isn’t happening.

Well I just found the cause.

When creating a window, I was setting self.Visible = false for cases where a window would be cancelled for whatever reason internally, so the window wouldn’t flash on the screen. I was then showing the window with self.Show if the operation was to complete.

Just checked in the Debugger, and calling self.Show does NOT set the Visible property to True. I have to explicitly set the Visible property back to true. Not intuitive, since calling self.Show makes the window visible regardless of the Visible property. So either something changed, or I’ve been under the misapprehension (for over a decade?) that calling .show sets .visible to true.

Anyway, after setting self.Visible = true, the menus work as they should.

Funny thing is, I can’t reproduce this in an example project. If I make an empty project and put this in a Window’s Open event:

Self.Visible = false
Speak Self.Visible

The result is “True”.

So why in my app, Visible stays false unless I switch it back to true, even after calling, is still an unknown.

I think it has something to do with the order of calling, if you read the notes here you see what i mean:

Well, according to that, setting the visible property is the same as using hide or show, which has been my understanding all along (although it’s not quite the same, since show also activates the window, brings it to the front – there are two ways to do it for good reasons), and which also corresponds to the way things have always worked. I spent quite a while today with a test app to try to reproduce this problem, and I never could reproduce it. There should never be a situation where a window which is showing, which is visible, has a .Visible property that reads false, but that’s what happening in my app. How it’s happening, I have absolutely no idea.