Enable menu items?

You cannot enable a menu item that has no handler.

[quote=139112:@Alexander van der Linden]Syed,

I have copied the faulty Menubar into a blank project with the same outcome. Would you care to give it a try?

Sander

It is very small, 28 kb here.[/quote]
The problem seem to have been caused by the Index value other than -2147483648. If the Index value is set to -2147483648 then the “Enabled = True” for the MenuItem “dbopenItem” is accepted and the Build is completed without any errors. Here is the code in the Window1.EnableMenuItems event handler.

// // Code in the "Window1.EnableMenuItems" event handler. // dbopenItem.Enabled = True

Seems the MenuItem “dbopenItem” can be enabled as described above without any handler assigned to this menu item. Same is already shown in the previous sample projects “MenuExample” and “MenuExample2” above.

Sayed,

I will try that tomorrow. Thanks very much!

Michel,

You can indeed enable without any handler specified. Thanks for your time!

Fine and well. But what is the point to have an enabled menu item without a handler to do whatever the menu is supposed to do ?

How do you execute code when a menu item is selected by the user ?

[quote=139150:@Michel Bujardet]
Fine and well. But what is the point to have an enabled menu item without a handler to do whatever the menu is supposed to do ?

How do you execute code when a menu item is selected by the user ?[/quote]
The investigation conducted thus far and the solution provided was based on the face value of the reported problem.

Indeed. Congratulations for your perspicacity. So now the user can select a menu item that does nothing. Big progress :wink:

… in the spirit of software fault finding.

Please share the results.

Here are results of further testing.

The Index value other than -2147483648 is already discussed here in the forum. If, for example, the MenuItem “dbopenItem” has been assigned Index value 100 then this can be accesses with following code in the “EnableMenuItems” event handler.

[code]
//
// On Windows 7, Xojo 2014r2.1
//
// Code in the “Window1.EnableMenuItems” event handler.
//
// Assign Index value 100 to MenuItem “dbopenItem”
//
// If the index (100) is omitted below then compiler shows error text “This item does not exist”
// and the “Enabled” property is highlighted in yellow colour. The “Index” proprty is described as
// “The number of the selected MenuItem when it is part of an array.” in LR.
//
// Contrary to the claim elsewhere in the discussion above, even if a handler is assigned
// to the MenuItem “dbopenItem” and the Index value is not used in the code below then compiler still
// shows the same error as in paragraph above.
//
dbopenItem(100).Enabled = True

//
// As already discussed above, if the Index value is set to -2147483648 then there is no need to
// specify any index in the code and the following code compiles without any error.
//
dbopenItem.Enabled = True[/code]

The “MenuItem.Index” property does not have any reference to the default value of -2147483648 in LR and its implications on the code. This missing information may already have been reported against the LR.

On Windows 7, in Xojo 2014r2.1, if name of a menu item is left blank then, after the dialogue box warning about this blank name, the Xojo IDE crashes.

It seems that if (LR is opened from inside Xojo with F1 on Windows 7, Xojo 2014r2.1 and then Xojo IDE is closed and the) LR is left open then Xojo IDE does not start. The LR must be closed for Xojo IDE to start.

Syed,

thanks for your investigation. You are right! When setting the index to the (default) value of -2147483648 no compiler errors occur.

Wether there is an handler specified or not does not influence this.

I think I know what happened:

  • I use ver 2014r1.1 for building (license)
  • I use ver 2014r2.1 for coding. Somewhere in that process the index values where replaced by sequential nrs starting with 1.

Glad we (you) found out as it is a very annoying bug (or undocumented feature)!

By assigning an Index to a MenuItem you create the equivalent of a ControlSet, a “MenuItemSet” so to say. The value of -2147483648 is removing the MenuItem from the MenuItem set. By the way -2147483648 is the lowest value a signed Int32 can be.

So if you use a MenuItem set, you need to use the Index to work with an item in the set. There is no bug in the MenuItem class (at least not regarding the Index property).

Hello Eli,

the bug I was referring to is the ‘automatic’ ordering. I certainly didn’t do that.
BUT, I have tried to work with the index as well,

MainMenuBar.Item(2).Enable

Didn’t work either.

However it remains uncodumented in LR in “MenuItem.Index”.

This can be pointed out to “Paul Lefebvre” and he may update the LR document as necessary,

[quote=139225:@Alexander van der Linden]
the bug I was referring to is the ‘automatic’ ordering. I certainly didn’t do that.[/quote]
Which platform and Xojo revision? On Windows 7, Xojo 2014r2.1, all new menu items get the default index value of -2147483648.

[quote=139225:@Alexander van der Linden]Hello Eli,

the bug I was referring to is the ‘automatic’ ordering. I certainly didn’t do that.
BUT, I have tried to work with the index as well,

MainMenuBar.Item(2).Enable

Didn’t work either.[/quote]
I downloaded your example above, and there are several issues:

  1. You are calling addchapterItem.Enable in App’s EnableMenuItems event. But your App.MenuBar property is set to Nil. Hence the error with addchapterItem marked in yellow.
    Set App.MenuBar to “MainMenuBar1” in the project explorer and this error will go away.

  2. Delete all Indexes. Index is only used for MenuItem arrays, which is not the case here, since not one of your menu items in MainMenuBar1 is a MenuItem array or part of it. As soon as you have done that, you can use the Enable() method and/or the Enabled property in EnableMenuItems without any problems.

The moral is : do not delete the default menu bar or mess with index values if you do not know what it does…

I have never observed indexes changing by themselves. But that’s just me… I am surely mistaken.

Just a note: I had the same problem, the menu was all done correctly but it still was disabled.

Then I changed the Window Frame Type from Modal Dialog to Rounded Window.

So, the type of window frame you are in will determine if the menu works.