从数据库里取得数据,动态的生成菜单。我的代码如下:
procedure TForm1.FormCreate(Sender: TObject);
var
  theActionClients1:TActionClients;
  theActionClients2:TActionClientItem;
begin
  theActionClients1:=ActionManager1.ActionBars[0].Items;
  theActionClients2:=theActionClients1.Add;
  theActionClients2.Caption:='111';
  theActionClients2.Visible:=True;
  theActionClients2.DisplayName:='222';  ShowMessage(IntToStr(ActionManager1.ActionBars[0].Items.Count));
end;
程序运行起来显示的结果为,但是在ActionMainMenuBar里就是看不见按钮,郁闷!

解决方案 »

  1.   

    把form的mainmenu 属性设置为你创建的菜单
      

  2.   

    楼上的,我说的不是常规的菜单。我根本就没有用常规的菜单,我用的是ActionManager做WinXP效果的菜单。
      

  3.   

    往actionmenubar里动态加入菜单我以前也试过,没有成功,呵呵
    后来索性预先做好一定数量的taction,并生成菜单,在运行时控制它们的visible属性。希望看到更好的答案出现。
      

  4.   

    可是有意思的事情是,如果我预先在ActionManager的ActionBars里放一个菜单,再运行,两个就全显示出来了,也不知道为什么?
      

  5.   

    所以现在的结果是,预先在ActionManager的ActionBars里放一个菜单,设置成不可见,再运行就出现创建的Caption为“111111”的菜单了。
    但是问题又来了,因为这个办法毕竟不是正路呀,想在"111111"下在创建菜单项目就又看不见了。
    var
      theActionClients1:TActionClients;
      theActionClients2:TActionClientItem;
    begin
      theActionClients1:=ActionManager1.ActionBars[0].Items;
      theActionClients2:=theActionClients1.Add;
      theActionClients2.Caption:='111111';
      theActionClients2.Visible:=True;
      //以下是后加的
      theActionClients1:=theActionClients2.Items;
      theActionClients2:=theActionClients1.Add;
      theActionClients2.Caption:='222222';
      theActionClients2.Visible:=True;
    end;
    仍然看不见"222222",但是情况下是不可能在设计期间去创建一个菜单项目,然后设置成不可见了,因为"111111"在设计期间根本不存在...:(
      

  6.   

    //以下是后加的
      theActionClients1:=theActionClients2.Items;
      theActionClients2:=theActionClients1.Add;
      theActionClients2.Caption:='222222';
      theActionClients2.Visible:=True;
    这段代码的意思是:在"111111"的下面再挂一层菜单"222222"。很遗憾,显示不出来。
      

  7.   

    我实验出来了,创建"111111"以后还需要动态的创建一个ActionList里的Action,然后把这个Action和"111111"联系起来就显示出来了。
    这个东西可真麻烦!
    要是动态加载的话需要创建的东西可真不少呀,麻烦呀