I want to clone an entire TMenuItem with it's children to another TPopupMenu. Here is a nice code:
function CloneMenuItem(SourceItem: TMenuItem): TMenuItem;
var
I: Integer;
Begin
with SourceItem do
Begin
Result := NewItem(Caption, Shortcut, Checked, Enabled, OnClick, HelpContext, Name + 'Copy');
for I := 0 To Count - 1 do
Result.Add(CloneMenuItem(Items[I]));
end;
end;
The following works just fine (b1 is a PopupMenu1.TMenuItem with sub menus):
PopupMenu2.Items.Add(CloneMenuItem(b1));
The problem is that I can't clone an entire TPopupMenu if the SourceItem is the root item. e.g :
PopupMenu2.Items.Add(CloneMenuItem(PopupMenu1.Items));
Wont work. All I can see is 1 Item, as if it was a separator.
TMenuItem.Parent == nil
will do?) – Ubana