//因为PopupMenu1中可能存在多级菜单,所以要完整复制过去,要用递归函来复制//以下代码机上运行通过了//递归函数procedure TForm1.CopyMenuItem(MenuItem, SubMenuItem: TMenuItem);var i: integer; item: TMenuItem;begin if Assigned(MenuItem) and Assigned(SubMenuItem) then begin item:= TMenuItem.Create(MenuItem); item.Caption:= SubMenuItem.Caption; item.OnClick:= SubMenuItem.OnClick; //事件也一起复制 MenuItem.Add(item); for i:= 0 to SubMenuItem.Count-1 do begin CopyMenuItem(item, SubMenuItem.Items); end; end;end;//PopupMenu2里添加一项第7项,然后把PopupMenu1里所有内容做为第7项的子菜单添加进去procedure TForm1.Button1Click(Sender: TObject);var i: integer; Item: TMenuItem;begin Item:= TMenuItem.Create(PopupMenu2); Item.Caption:= 'PopupMenu1复制过来的'; PopupMenu2.Items.add(Item); for i:= 0 to PopupMenu1.Items.Count - 1 do CopyMenuItem(Item, PopupMenu1.Items);end;