当打开一个MDIChild 时在MDIForm的MainMenu1->N3下添加一个动态菜单
关闭MDIChild 时删除该动态菜单,该怎样实现

解决方案 »

  1.   

    procedure TForm1.AddButtonClick(Sender: TObject);
    var
      index: Integer;
      NewItem: TMenuItem;
    begin
      for index := 0 to 3 do
      begin
        NewItem := TMenuItem.Create(PopupMenu1); // create the new item
        PopupMenu1.Items.Add(NewItem);// add it to the Popupmenu
        NewItem.Caption := 'Menu Item ' + IntToStr(index);
        NewItem.Tag := index;
        NewItem.OnClick = PopupMenuItemsClick;// assign it an event handler
      end;end;
      

  2.   

    打开时:
    var
      MmItem: TMenuItem;
    begin
      MmItem := TMenuItem.Create(Form1.MainMenu1);
      MmItem.Caption := '新加的';
      Form1.MainMenu1.Items[0].Insert(1,MmItem);    //假设N3为第2个
    end;关闭:
    procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Form1.MainMenu1.Items[0].Delete(2);
    end;————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  3.   

    添加可以用
      Formname.mainmenu1.items.add(TMenuitem);
      Formname.mainmenu1.items.caption;卸载时可以用:
      formname.mainmenu1.items.itemsname.destroy;具体操作自己去试;