数据库结构为MenuName Caption  SetID
————————————————
wrer    文件    10
jhjt       文件1    1010
hj    文件2    1012
fh    -    1011
u    编辑    11
ry    编辑1     1110
hjkhhg    编辑2    111011
g    操作      12怎样根据以上数据库生产如下菜单文件        编辑       操作
 |_文件1     |_编辑1    
 |_文件2     |_编辑2

解决方案 »

  1.   

    给你一个例子,应该会有帮助的。
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,StdCtrls, ExtCtrls,Menus;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        procedure MyPopupHandler(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      MyMainMenu: TMainMenu;
      MyPopUpMenu: TPopUpMenu;
      MySubItems: array[0..3] of TMenuItem;
      MyPopUpItems: array[0..3] of TMenuItem;
      i: Integer;
    implementation{$R *.dfm}
    procedure TForm1.MyPopupHandler(Sender:TObject);
    begin
     with Sender as TMenuItem do
     begin
     //在信息对话框中显示选中菜单项的Caption属性
      ShowMessage(Caption);
     end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      MyItem:array[0..2] of TMenuItem;
    begin
      MyMainMenu:=TMainMenu.Create(Self);
      //创建三个子菜单
      for i:=0 to 2 do begin
       MyItem[i]:=TMenuItem.Create(Self);
       MyItem[i].Caption:='子菜单'+IntToStr(i)+'(&'+IntToStr(i)+')';
       MyMainMenu.Items.Add(MyItem[i]);
      end;
      for i:=0 to 3 do begin
       MySubItems[i]:=TMenuItem.Create(Self);
       MySubItems[i].Caption:='主菜单项'+IntToStr(i)+'(&'+IntToStr(i+1)+')';
       MyMainMenu.Items[0].Add(MySubItems[i]);
       //指定菜单项的OnClick事件的处理过程
       MySubItems[i].OnClick:=MyPopUpHandler;
      end;
      //将第2个菜单项设置为分隔条
      MySubItems[1].Caption:='-';
      //设置竖向分隔条
      MySubItems[3].Break:=mbBarBreak;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      MyPopUpMenu:=TPopUpMenu.Create(self);
      for i:=0 to 3 do
      begin
       MyPopUpItems[i]:=TMenuItem.Create(Self);
       //设置菜单项的Caption属性
       MyPopUpItems[i].Caption:='弹出菜单项'+IntToStr(i)+'(&'+IntToStr(i+1)+')';
       MyPopUpMenu.Items.Add(MyPopUpItems[i]);
       //指定菜单项的OnClick事件的处理过程
       MyPopUpItems[i].OnClick:=MyPopupHandler;
      end;
    end;procedure TForm1.Button3Click(Sender: TObject);
    begin
      //通过按钮激活弹出式菜单
      MyPopUpMenu.Popup(Form1.Left+60,Form1.Top+60);
    end;end.
      

  2.   

    可先去网上查找c#,VB.NET生成的网页菜单脚本,作相应的修改就可以了!
      

  3.   

    你把数据库中的字段取出来,把菜单的caption改成取出的字段名不就可以了啊
      

  4.   

    我自己有一个,不过有缺点,哪位高手帮忙修修
    procedure TFrm_Main.LoadMainMenu;
    var
        curID: String;
        ImageIndex: Integer;
        level: Integer;
        MainMenuItem, MenuItem: TMenuItem;
        //MenuItem: Array[0..9] of TMenuItem;
        //MenuItem: TMenuItem;
    begin
      //初始化变量
      level:=0 ;
      curID:= '';
      //遍历数据表,利用编码字段记录排序规律,依次添加
      with CDS_Sys_Menu do
      begin
        try
          Close;
          CommandText:= 'Select * from Sys_Menu where SeptID Like '+ QuotedStr(CurID+'%')
                     +' and Len(SeptID)='+ (IntToStr(Length(curID)+2)) +' order by SeptID';
          Open;
          First;
          while not eof do
          begin
            curID:=Trim(FieldByName('SeptID').AsString);
            begin
              if Not FieldByName('ImageIndex').IsNull then
                ImageIndex:= FieldByName('ImageIndex').AsInteger;
              MainMenuItem:= TMenuItem.Create(MainMenu1);
              MainMenuItem.Name:= Trim(FieldByName('MenuName').AsString);
              MainMenuItem.Caption:= Trim(FieldByName('Caption').AsString);
              MainMenu1.Items.Add(MainMenuItem);
            end;
              LoadMainItem(MainMenuItem, curID);
              Next;
          end;
        finally;
          close;
        end;
      end;
    end;
    Function TFrm_Main.LoadMainItem(MainMenuItem: TMenuItem;curID: String) :Integer;
    var
      MenuItem: TMenuItem;
    begin
            with CDS_Tmp do
            begin
              Close;
              CommandText:= 'Select * from Sys_Menu where SeptID Like '+ QuotedStr(CurID+'%')
                     +' and Len(SeptID)='+ (IntToStr(Length(curID)+2)) +' order by SeptID';
              Open;          while not eof do
              begin
                MenuItem:= TMenuItem.Create(MainMenu1);
                MenuItem.Name:= Trim(FieldByName('MenuName').AsString);
                MenuItem.Caption:= Trim(FieldByName('Caption').AsString);
                MainMenuItem.Add(MenuItem);
                LoadMainItem(MenuItem, Trim(CDS_Tmp.FieldByName('SeptID').AsString));
                Next;    
              end;
            end;end;
      

  5.   

    delphi的help目錄中有一個,menu2也就是上面帖的代碼