谢谢各位的帮助,昨天已经顺利完成了动态地创建POPUPMENU!菜单是一维的.但是又该如何在运行中删除动态创建的 POPUPMENU 的某个菜单项呢?代码应该如何编写呢?请各位给指点一下,先谢了!

解决方案 »

  1.   

    var i:integer;
       popupmenu1.Items.Delete(i);
      

  2.   

    Dynamically creating a PopupMenu In the Private section of the Interface of your unit
     Put the follwing (You may need to make more than one
     'MyClick' type of Procedure) :  NewMenu : TPopUpMenu;
      Procedure MenuPopItUp(Sender : TObject);
      Procedure MyClick(Sender : TObject); Then make a your click procedure(s)Procedure TForm1.MyClick(Sender : TObject);
    Begin
       ShowMessage('This is my new dynamically created PopupMenu');
       // Or do what evere you need to do here.
    End;
    // This procedure gets called when you right-click (OnMouseDown) on
    // your choosen component
    Procedure TForm1.MenuPopItUp(Sender : TObject);
    var
      mi, msub: TmenuItem;
    Begin
      with (Sender as TPopupMenu) do begin
    // Create our first MenuItem
         mi := TMenuItem.Create(self);
        with mi do begin
    // Lets give our new item a caption
          Caption := 'First';
    // Set the MyClick procedure to be 'associated'
    // with this MenuItem
          OnClick := MyClick;
        end;
    // Lets put the new MenuItem in the PopupMenu
        Items.Insert(0, mi);        mi := TMenuItem.Create(self);
        with mi do begin
          Caption := 'Sub';
          msub := TMenuItem.Create(self);
          with msub do begin
            Caption := 'Sub1';
            OnClick := MyClick;
          end;
          Insert(0, msub);      msub := TMenuItem.Create(self);
          with msub do begin
            Caption := 'Sub2';
            OnClick := MyClick;
          end;
          Insert(1, msub);
        end;
        Items.Insert(1, mi);
      end;
    End;
      

  3.   

    看错
    PopupMenu1.Items.Delete(index);
      

  4.   

    注意一点,如果使用for循环,请使用 Downto
        for i:=PopMenu.Items.Count-1 downto 0 do
          if (PopMenu.Items[i].Caption='aaa') then
          begin
            PopMenu.Items.Delete(i);
          end;