如题

解决方案 »

  1.   

    lyguo(初学者) 大哥你要是会就写的详细点我分都给你,你这样我看不明白
      

  2.   

    呵呵,
    1:创建一个菜单项对象
    TMEnuItem.create(nil)
    2:然后通过数据库,设置这个菜单项对象的性性。比如:caption,onClick事件的处理程序
    3:然后
    menu1.items.add(你创建的对象)
    4:完成了。。
      

  3.   

    给你看个例子吧:procedure InitMenu;
    var
      act: TAction;
      mnu,mnuP: TMenuItem;
      obh: TmxOutlookBarHeader;
      ob: TOutlookButton;
      tb: TToolButton;
      i: Integer;
      str: string;
    begin
      try
        ToolBar.ShowCaptions:=False;
        ToolBar.AutoSize:=False;
        ToolBar.ButtonHeight:=38;
        ToolBar.ButtonWidth:=39;
        Str:='';
        for i:=0 to 127 do Str:=Str+'1';//处理超级用户    with MainDataModule.FuncDefDataSet do
        begin
          RemoteServer:=MainDataModule.CurConnection;
          Open;
          First;
          while not Eof do
          begin
            mnu:=TMenuItem.Create(Self);
            mnu.Name:=Format('TMenuItem%d',[FieldByName('ID').AsInteger]);
            mnu.Tag:=FieldByName('ID').AsInteger;
            if FieldByName('iParentID').AsInteger>0 then
            begin
              act:=TAction.Create(Self);
              act.Name:=Format('TAction%d',[FieldByName('ID').AsInteger]);
              act.Caption:=FieldByName('sCaption').AsString;
              act.Category:=FieldByName('sCategory').AsString;
              act.Hint:=FieldByName('sHint').AsString;
              act.ImageIndex:=FieldByName('iImageIndex').AsInteger;
              act.Visible:=(FieldByName('bVisible').AsInteger=1) and (FieldByName('bSuppermanVisible').AsInteger=0);
              if FunctionStr=Str then act.Visible:=True;
              act.Tag:=FieldByName('ID').AsInteger;
              if act.Caption='帮助' then
                act.OnExecute:=SysHelpExecute
              else if act.Caption='注销登录' then
                act.OnExecute:=LogoutMgrExecute
              else if act.Caption='退出系统' then
                act.OnExecute:=CloseSystemMgrExecute
              else
                act.OnExecute:=ExecuteMdiForm;
              act.ActionList:=ActionList;
              mnu.Action:=act;
              //mnuP:=MainMenu.Items.Find(FieldByName('sCategory').AsString);
              mnuP:=self.FindComponent(Format('TMenuItem%d',[FieldByName('iParentID').AsInteger])) as TMenuItem;
              if act.Visible then
              if FieldByName('iInOutlook').AsInteger>0 then
              begin
                obh:=self.FindComponent(Format('TmxOutlookBarHeader%d',[FieldByName('iParentID').AsInteger])) as TmxOutlookBarHeader;
                ob:=TOutlookButton.Create(Self);
                ob.Action:=act;
                ob.LargeImages:=FunImageList;
                ob.SmallImages:=FunImageList;
                ob.ImageIndex:=act.ImageIndex;
                ob.Caption:=FieldByName('sOutlookCaption').AsString;
                obh.AddButton(ob);
              end;
              if act.Visible then
              if FieldByName('bInToolbar').AsInteger=1 then
              begin
                tb:=TToolButton.Create(ToolBar);
                tb.Name:=Format('TToolButton%d',[FieldByName('ID').AsInteger]);
                tb.AutoSize:=False;
                //tb.Parent:=ToolBar;
                tb.Action:=act;
                //tb.:=tbIndex;
              end;
            end
            else begin
              mnu.Caption:=FieldByName('sCaption').AsString;
              mnuP:=MainMenu.Items;
              if FieldByName('iInOutlook').AsInteger=0 then
              begin
                obh:=TmxOutlookBarHeader.Create(Self);
                obh.Name:=Format('TmxOutlookBarHeader%d',[FieldByName('ID').AsInteger]);
                obh.Caption:=FieldByName('sOutlookCaption').AsString;
                obh.Color:=15002091;
                OutlookBar.AddHeader(obh);
              end;
            end;
            mnuP.Add(mnu);
            if (FieldByName('bHasLine').AsInteger=1) and mnu.Visible then
            begin
              mnu:=TMenuItem.Create(Self);
              mnu.Caption:='-';
              mnuP.Add(mnu);
            end;
            //ActionManager.AddCategory()
            Next;
          end;
          for i:=ToolBar.ComponentCount-1 downto 0 do
            (ToolBar.Components[i] as TToolButton).Parent:=ToolBar;
        end;
      finally
        ToolBar.ShowCaptions:=False;
        ToolBar.AutoSize:=False;
        ToolBar.ButtonHeight:=38;
        ToolBar.ButtonWidth:=39;
        OutlookBar.ActiveHeader:=OutlookBar.GetHeaderByIndex(0);
      end;end;
      

  4.   

    谁有例子能给小弟发一份吗?[email protected]