MenuItem.Clone
From Xojo Documentation
Makes a copy of the MenuItem and its children if any. Mac does not permit duplicate MenuItems, so you will need to create clones of any MenuItems that are now being used in two or more locations.
Notes
The clone contains only new objects so it does not share any reference with the original MenuItem. This is especially useful for Mac applications because the Mac framework does not allow the same MenuItem to be used in different places, e.g. in several MenuBars. If you do so, a MenuHasParentException is raised. To avoid the problem, remove duplicate MenuItems and create clones of the original MenuItem instead.
Clone and MenuItem Subclasses
If you intend to clone an instance of a MenuItem subclass, you should overload the copy constructor otherwise the values of your subclass properties will not be cloned. Suppose you have a MenuItem subclass CustomMenuItem, you can implement a copy Constructor like this:
The constructor copies the passed CustomMenuItem, and then copies the values of CustomMenuItem properties.
Super.Constructor(copy)
// Assign your custom parameters
Self.Foo = copy.Foo
End Sub
This constructor now allows the Clone method to successfully copies the custom properties:
and get a copy of item, including all CustomMenuItem properties.
Sample Code
Whenever you need to use the same MenuItem in different places, use the Clone method to create a new copy of the MenuItem and its children, if any.
Var myClone As MenuItem
myClone = mi.Clone // Creates an independent copy of "mi"
See Also
MenuHasParentException exception.