我的动态菜单在加载的时候有错误?
unit code;interfaceuses
    Menus,SysUtils;  procedure menushow(Sender: TObject);
var
  w:integer;
  MyMainMenu: TMainMenu;
  MyPopUpMenu: TPopUpMenu;
  MySubItem1,MySubItem2 : TMenuItem;
  MySubItems: array[0..3] of TMenuItem;
  MyPopUpItems: array[0..3] of TMenuItem;implementationuses main;procedure menushow(Sender: TObject);
var
MyItem: array[0..2] of TMenuItem;
MySubItems:  array[0..3] of TMenuItem;
i: Integer;
j: integer;
begin
   for j := 0 to 2 do
    begin
    MyItem[j] := TMenuItem.Create(frmmain.Owner);
    MyItem[j].Caption := 'New item ' + IntToStr(j);
    MyMainMenu.Items.Add(MyItem[j]);
    end;  for i := 0 to 3 do
    begin
    MySubItems[i] := TMenuItem.Create(frmmain.Owner);
    MySubItems[i].Caption := 'New item ' + IntToStr(i);
    //MySubItems[i].OnClick := MyPopUpHandler;
    MyMainMenu.Items[0].Add(MySubItems[i]);
    end;
end;end.上面一段CODE中有错误,有高手能帮我指出来吗?
并且说是为什么?请了!!!!

解决方案 »

  1.   

    我这儿有一个例子,不知道是不是你希望得到的结果,
    var
      Form1: TForm1;
      MyMainMenu:TMainMenu;
      MySubItem:array [0..4] of TMenuItem;
      i:integer;
    implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    var
      MyItemMenu:array [0..2] of TMenuItem;
    begin
      MyMainMenu:=TMainMenu.Create(self);  //建立主菜单
      for i:=0 to 2 do
      begin
        MyItemMenu[i]:=TMenuItem.create(self);    //建立三个菜单项
        MyItemMenu[i].Caption :='主菜单'+IntToStr(i);
        MyMainMenu.Items.Add(MyItemMenu[i]);
      end;  for i:=0 to 4 do
      begin
        MysubItem[i]:=TMenuItem.Create(Self);  
        MySubItem[i].Caption :='子菜单项'+IntToStr(i);
        MyMainMenu.Items[0].add(MySubItem[i]);    //在第一个菜单项建立5个子菜单项
      end;  for i:=0 to 1 do
      begin
        MysubItem[i]:=TMenuItem.Create(Self);
        MySubItem[i].Caption :='子菜单项'+IntToStr(i);
        MyMainMenu.Items[1].add(MySubItem[i]);  //在第一个菜单项建立2个子菜单项
      end;  for i:=0 to 4 do
      begin
        MysubItem[i]:=TMenuItem.Create(Self);
        MySubItem[i].Caption :='子菜单项'+IntToStr(i);
        MyMainMenu.Items[2].add(MySubItem[i]);  //在第一个菜单项建立5个子菜单项
      end;end; 建立右键菜单用同样的方法