From Xojo Documentation
|You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!|
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.
// Assign your custom parameters
Self.Foo = copy.Foo
This constructor now allows the Clone method to successfully copies the custom properties:
and get a copy of item, including all CustomMenuItem properties.
Var myClone As MenuItem
myClone = mi.Clone // Creates an independent copy of "mi"