EditMenu.Clone is not correct in 19r1.1?

Hi All,

I’m getting this error on compile when I try to create a popup clone of the existing menus - File, Edit, View, Help. The error is:

ccMainTools.cvToolbutton.MouseDown, line 14 Type mismatch error. Expected class MenuItem, but got Int32 Dim em As MenuItem = EditMenu.Clone

Further deconstruction of the clone lines is reporting that EditMenu does not exist. However, there is an EditMenu in my MenuBar menu class and it autocompletes properly.

The code is as simple as I can get:

[code]Dim fm, em, vm, hm As MenuItem

fm = FileMenu.Clone
em = EditMenu.Clone
vm = ViewMenu.Clone
hm = HelpMenu.clone[/code]

Ideas? What have I overlooked? The MenuItem.Clone entry in the language ref is not helpful.

19r1.1, Mac and Linux

does the window you’re doing this in have the menu bar set as its menu bar ?
or are you trying to clone the app one ?

What about:

Dim fm As MenuItem = MainMenuBar.Child(“FileMenu”).Clone

That’s the problem - I am placing this code in a container on the main window where the menu exists. Odd that the autocomplete likes it …

ah
so the menu is not attached to the container but to the window that contains it
maybe something like

Dim w As Window = Self.TrueWindow
Dim mb As MenuBar = w.MenuBar
If mb Is Nil Then 
  mb = app.MenuBar
End If
If mb Is Nil Then
  Return False
End If
dim mi as Menuitem = mb.Child("EditMenu")
Dim em As MenuItem = mi.Clone

break

in case you swap the menu bar dynamically etc
of course with more checks for nil objects along the way

MainMenuBar could refer to the wrong one
This always refers to the one attached to the window, assuming there is one, or the one attached to the app, if there is one