建立一个TMenuItem的数组,然后添加。
MenuItems: array of TMenuItem;
SetLength(MenuItems, 5);
//建立这些菜单
....
...
....
.......   //然后添加

解决方案 »

  1.   

    我也这样做了,但是总是告诉我说什么没有初始化。我的程序是
    Item1:=TMenuItem.Create(MainMenu1);
      Item1.Caption :='菜单文件';
      MainMenu1.Items.Add(Item1);
      if OpenDialog1.Execute then
        begin
         // SetLength(AItems,OpenDialog1.Files.Count-1);
          for i:=0 to OpenDialog1.Files.Count-1 do
            begin
              //AItems[i]:=AItems[i].Create(MainMenu1);提示这句有问题?why?
              Item2:=TMenuItem.Create(MainMenu1);
              Item2.Caption :=extractFileName(OpenDialog1.Files[i]);
              Item1.Add(Item2); 
            end;
           end;
    做的就有点类似解霸的打开多个文件。能够动态的添加一个列表文件。
      

  2.   

    我用的不是数组(const AItems:array of TMenuItem)但是,如果用Item2如何能够选择动态菜单里面的item,因为添加多个文件后,itesm2已经移动到最后一个菜单项了……