From Xojo Documentation
|You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!|
Makes a copy of the DesktopMenuItem 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.
The clone contains only new objects so it does not share any reference with the original DesktopMenuItem. This is especially useful for Mac applications because the Mac framework does not allow the same DesktopMenuItem to be used in different places, e.g. in several DesktopMenuBars. 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 DesktopMenuItem 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:
origMenu.Foo = 12
Var copyMenu As DesktopMenuItem = origMenu.Clone
and get a copy of item, including all CustomMenuItem properties.
Var myClone As DesktopMenuItem
myClone = mi.Clone // Creates an independent copy of "mi"