Enable menu items?

I try to enable menu items in the App.EnableMenuItems event. That puzzles me…

dbopenItem.enable ->compiler error: That item does not exist
dbopenItem.Enabled = True ->compiler error: That item does not exist
MainMenuBar.Item(11).Enabled = True->runtime error: Out of bounds exception

The 11 is the index nr associated with the menu item

Without the EnableMenuItems event the menubar is visible and working, albeit that some items are not disabled, which I try to achieve…

do you have a menubar assigned in app.menubar?

me.menubar = MainMenuBar

  • In Xojo 2014r2.1, create a new Desktop project called “MenuExample”.

  • In the Project “CONTENTS” click on the “MainMenuBar”

  • In the menu “Toolbar” click on the “Apple”, “Windows” or “Linux/Penguin” icon as needed.

  • Click on the “Toolbar” icon that has “Tooltip” text = “Create a new menu in this menu bar.”. An “Untitled” menu should appear in the menu bar. Give it the Name = “mnuDatabase” and Text = “Database”.

  • Click on the “Toolbar” icon that has “Tooltip” text = “Create a new menu in this menu bar.”. An “Untitled” menu should appear in the menu bar. Give it the Name = “mnuTextfile” and Text = “Text File”.

  • Click on the new menu item “Database”.

  • Click on the “Toolbar” icon that has “Tooltip” text = “Create a new item in this menu.”. An “Untitled” item will appear under the “Database” menu. Name this item as “mnuDBOpen”.

  • Click on the “Toolbar” icon that has “Tooltip” text = “Create a new item in this menu.”. An “Untitled” item will appear under the “Database” menu. Name this item as “mnuDBSave”.

  • Click on the new menu item “Text File”.

  • Click on the “Toolbar” icon that has “Tooltip” text = “Create a new item in this menu.”. An “Untitled” item will appear under the “Text File” menu. Name this item as “mnuTFOpen”.

  • Click on the “Toolbar” icon that has “Tooltip” text = “Create a new item in this menu.”. An “Untitled” item will appear under the “Text File” menu. Name this item as “mnuTFSave”.

  • Run the application. All the above created “Open” and “Save” menu items should be displayed as disabled. Exit the running application to return to Xojo IDE.

  • In the Project “CONTENTS” click on the “Window1”.

  • In the righ hand section in IDE, click on “ID” button at the top, then scroll down with the right had scroll bar to “Menus” section and make sure “Menu Bar” shows “MainMenuBar”. Just to be sure, select “None” and then select the “MainMenuBar” again.

  • From menu, select “Insert - Event Handler…”. This should display the “Add Event Handler to” dialogue box.

  • Select the “EnableMenuItems” from the list “Add Event Handler to Window1” and click on “OK” button to dismiss this dialogue box.

  • The IDE Code editor for “EnableMenuItems” should be displayed. Add the following code to enable the menu items.

mnuDBOpen.Enabled = True mnuDBSave.Enabled = True

  • Save the project, select “File - Save” from menu.

  • Run the application. Now the “Database” “Open” and “Save” menu items should be displayed as enabled.

  • Use the above example to see what may be causing the reported problem.

Thanks for your elaborate reply. I will certainly look into this and let you know.

If you’re assigning it in code, the compiler cannot know about the contents. Assign the menubar in the IDE.

Tim,

I’ve done that. App->appearance->menubar

[quote=137384:@Syed Hassan]- In Xojo 2014r2.1, create a new Desktop project called “MenuExample”.

  • In the Project “CONTENTS” click on the “MainMenuBar”

  • In the menu “Toolbar” click on the “Apple”, “Windows” or “Linux/Penguin” icon as needed.

  • Click on the “Toolbar” icon that has “Tooltip” text = “Create a new menu in this menu bar.”. An “Untitled” menu should appear in the menu bar. Give it the Name = “mnuDatabase” and Text = “Database”.

  • Click on the “Toolbar” icon that has “Tooltip” text = “Create a new menu in this menu bar.”. An “Untitled” menu should appear in the menu bar. Give it the Name = “mnuTextfile” and Text = “Text File”.

  • Click on the new menu item “Database”.

  • Click on the “Toolbar” icon that has “Tooltip” text = “Create a new item in this menu.”. An “Untitled” item will appear under the “Database” menu. Name this item as “mnuDBOpen”.

  • Click on the “Toolbar” icon that has “Tooltip” text = “Create a new item in this menu.”. An “Untitled” item will appear under the “Database” menu. Name this item as “mnuDBSave”.

  • Click on the new menu item “Text File”.

  • Click on the “Toolbar” icon that has “Tooltip” text = “Create a new item in this menu.”. An “Untitled” item will appear under the “Text File” menu. Name this item as “mnuTFOpen”.

  • Click on the “Toolbar” icon that has “Tooltip” text = “Create a new item in this menu.”. An “Untitled” item will appear under the “Text File” menu. Name this item as “mnuTFSave”.

  • Run the application. All the above created “Open” and “Save” menu items should be displayed as disabled. Exit the running application to return to Xojo IDE.

  • In the Project “CONTENTS” click on the “Window1”.

  • In the righ hand section in IDE, click on “ID” button at the top, then scroll down with the right had scroll bar to “Menus” section and make sure “Menu Bar” shows “MainMenuBar”. Just to be sure, select “None” and then select the “MainMenuBar” again.

  • From menu, select “Insert - Event Handler…”. This should display the “Add Event Handler to” dialogue box.

  • Select the “EnableMenuItems” from the list “Add Event Handler to Window1” and click on “OK” button to dismiss this dialogue box.

  • The IDE Code editor for “EnableMenuItems” should be displayed. Add the following code to enable the menu items.

mnuDBOpen.Enabled = True mnuDBSave.Enabled = True

  • Save the project, select “File - Save” from menu.

  • Run the application. Now the “Database” “Open” and “Save” menu items should be displayed as enabled.

  • Use the above example to see what may be causing the reported problem.[/quote]

No probems whatsoever. But what I noticed is that in my App all menuItems have an assigned an index number while starting from scratch they all have -2147483648 in red which is default I guess.

Not sure about the index value, have the same here as well and this does not seem to cause any problem. Guess there were few discussions in the forum about this index value, however have not been able to find those for reference.

removing the index values does not show any difference. Still compiler errors. Think I have to reconstruct the menu system.

There is definitely something wrong. I deleted the old menu, created a new one and assigned it via the IDE (several times). It doesn’t show.

Followed the same steps as outlined earlier on Xojo 2014r2.1 on Windows 7 to create a new Desktop application “MenuExample2”, no issues. The application runs without any error and the “Database” “Open” and “Save” menu items are displayed as enabled.

Only in this project the menu system does not behave as normal. Every other project is ok.

Richard Summers had the issue quite a while ago. He had removed the default menu bar if I remember right. The solution was to start a new project and drag all other controls and modules from the bugged one.

Just removed the default menu bar called “MainMenuBar” from the above mentioned “MenuExample2” project and added a new one called “MenuBar1”, that works just fine, by making sure that “App” and “Window1” have the new menu bar assigned.

Okay, I’ve tried everything.

  • deleting and building a new menusystem ->does not work, the enable method or enabled boolean is not recognized
  • building a new menu in another project… and copying ->does not work
  • I have copied the menusystem into a new project… -> does not work either…

Pfffff… I’m stuck.

There is something the matter with this… can’t figure.

Does the “MenuExample” above not work in the existing project when the existing menu has been removed and a new MenuBarX has been added?

There is no technical detail (names of the objects, settings, properties, exact text of the Xojo code, exact text of the reported error and so on) in the latest post above.

Has the fault picture not changed a tiny bit despite all the changes?

Do not use the exact same names of the menu items when creating a new MenuBarX, just to avoid repeating any mistakes being made. Instead use new names of the menu items, objects, properties and so on.

And take a few steps back, sometimes things appear a lot clearer from a slightly greater distance.

Keeping the above fact in view, compare the two meticulously to locate the fault.

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=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]

Alexander, all I had to do to enable dbopenItem was to add a menu handler for it to the window…

Ah… no Michael… try to ENABLE an menu item in the EnableMenuItem event…