unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, DB, ADODB, Grids, DBGrids;type
  TNotifyEvent = procedure (Sender:TObject) of Object;
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    Q_MenuItem: TADOQuery;
    procedure FormCreate(Sender: TObject);
    procedure NewForm2(Sender :TObject);
    procedure NewForm3(Sender :TObject);
  private
    { Private declarations }
    procedure CreateMainMenu;
    procedure GetMenuItemData(RootID :Integer);
    procedure GetHeadItemData;
    procedure CreateMenuItem(RootID :Integer);
    procedure AddMenuItem(RootID,ParentID :Integer);
    function FindItem(RootID,ID:Integer):TMenuItem;
  public
    { Public declarations }
    procedure MenuItemClickEvent(Tag :Integer);
  published
    { published declarations }  end;var
  Form1: TForm1;
  OnClick :TNotifyEvent;
implementationuses Unit2, Unit3;
procedure ExecSQL(Sender:TADOQuery; sSQL :string);
begin
  with Sender do
    begin
      Active :=False;
      SQL.Clear;
      SQL.Add(sSQL);
      Active :=True;
    end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
  CreateMainMenu;
end;procedure TForm1.GetMenuItemData(RootID: integer);
var sSQL :string;
begin
  sSQL :='Select ID,ItemName,ItemCaption, ItemOrder,ImageIndex,ParentID,RootID,Tag,IsCheck,IsEnable,IsVisible,ShortCut,ClickEvent From SR_SYS_MAINMENU Where '+
      'IsRoot=0 and RootID='''+IntToStr(RootID)+''' Order by ItemOrder ';
  ExecSQL(Form1.Q_MenuItem,sSQL);
end;procedure TForm1.GetHeadItemData;
var sSQL :string;
begin
  sSQL :='Select ID,ItemName,ItemCaption, ItemOrder,ImageIndex,Tag,IsCheck,IsEnable,IsVisible,ShortCut,ClickEvent From SR_SYS_MAINMENU Where '+
      'IsRoot=1  Order by ItemOrder ';
  ExecSQL(Form1.Q_MenuItem,sSQL);
end;procedure TForm1.CreateMainMenu;
var MainMenu: TMainMenu;
    MenuItem :Array of TMenuItem;
    i,HeadCount :integer;
begin
   MainMenu:= TMainMenu.Create(Self);
   MainMenu.AutoHotkeys :=maManual;
   MainMenu.AutoLineReduction :=maManual;
   // Create HeadMenu
  GetHeadItemData;
  HeadCount :=Q_MenuItem.RecordCount;
  SetLength(MenuItem,HeadCount);
  for i :=0 to HeadCount-1 do
    begin
      MenuItem[i] :=TMenuItem.Create(Self);
      MenuItem[i].Name := Trim(Q_MenuItem.FieldByName('ItemName').AsString);
      MenuItem[i].Caption := Trim(Q_MenuItem.FieldByName('ItemCaption').AsString);
      MenuItem[i].ImageIndex :=Q_MenuItem.FieldByName('ImageIndex').AsInteger;
      MenuItem[i].Tag:=StrToInt(Trim(Q_MenuItem.FieldByName('Tag').AsString));
      MenuItem[i].Checked :=StrToBool(Q_MenuItem.FieldByName('IsCheck').AsString);
      MenuItem[i].Enabled :=StrToBool(Q_MenuItem.FieldByName('IsEnable').AsString);
      MenuItem[i].Visible :=StrToBool(Q_MenuItem.FieldByName('IsVisible').AsString);
      MenuItem[i].ShortCut :=TextToShortCut(Trim(Q_MenuItem.FieldByName('IsVisible').AsString));
      MainMenu.Items.Add(MenuItem[i]);
      Q_MenuItem.Next;
    end;
  //Create MenuItem
  for i :=0 to HeadCount-1 do
    CreateMenuItem(i);end;procedure TForm1.CreateMenuItem(RootID: Integer);
var MenuItem :TMenuItem;
    i,ItemCount,ParentID :integer;
begin
  GetMenuItemData(RootID);
  ItemCount :=Q_MenuItem.RecordCount;
  for i :=0 to ItemCount-1 do
    begin
      ParentID :=Q_MenuItem.FieldByName('ParentID').AsInteger;
      MenuItem :=TMenuItem.Create(Self);
      AddMenuItem(RootID,ParentID);
      Q_MenuItem.Next;
    end;
end;procedure TForm1.AddMenuItem(RootID,ParentID :Integer);
var ParentItem,MenuItem :TMenuItem;
    P: ^Integer;
begin
  ParentItem :=FindItem(RootID,ParentID);
  if ParentItem <> nil then
    begin
      MenuItem :=TMenuItem.Create(Self);
      MenuItem.Name := Trim(Q_MenuItem.FieldByName('ItemName').AsString);
      MenuItem.Caption := Trim(Q_MenuItem.FieldByName('ItemCaption').AsString);
      MenuItem.ImageIndex :=Q_MenuItem.FieldByName('ImageIndex').AsInteger;
      MenuItem.Tag:=StrToInt(Trim(Q_MenuItem.FieldByName('Tag').AsString));
      MenuItem.Checked :=StrToBool(Q_MenuItem.FieldByName('IsCheck').AsString);
      MenuItem.Enabled :=StrToBool(Q_MenuItem.FieldByName('IsEnable').AsString);
      MenuItem.Visible :=StrToBool(Q_MenuItem.FieldByName('IsVisible').AsString);
      MenuItem.ShortCut :=TextToShortCut(Trim(Q_MenuItem.FieldByName('IsVisible').AsString));
      P :=MethodAddress(Trim(Q_MenuItem.FieldByName('ClickEvent').AsString));
      OnClick :=P^;//这里有错误该如何解决
      ParentItem.Add(MenuItem);
    end
  else
    begin    end;
end;function TForm1.FindItem(RootID, ID: Integer):TMenuItem;
var j :Integer;
    sSQL :string;
    Query: TADOQuery;
begin
  Query :=TADOQuery.Create(Self);
  sSQL :='Select ID,ItemName,ItemCaption, ItemOrder,ImageIndex,ParentID,RootID,Tag,IsCheck,IsEnable,IsVisible,ShortCut,ClickEvent From SR_SYS_MAINMENU Where '+
      ' RootID='''+IntToStr(RootID)+''' and ID='''+IntTostr(ID)+''' Order by ItemOrder ';
  Query.Connection :=ADOConnection1;
  ExecSQL(Query,sSQL);
  Result :=nil;  if Query.RecordCount=1 then
    begin
      for j := 0 to ComponentCount - 1 do
        if Components[j] is TMenuItem then
          if UpperCase(Components[j].Name)=UpperCase(Trim(Query.FieldByName('ItemName').AsString)) then
          begin
            Result := TMenuItem(Components[j]);
            Break;
          end;
    end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
  CreateMainMenu;
end;procedure TForm1.NewForm2(Sender: TObject);
begin
  Form2.Show;
end;procedure TForm1.NewForm3(Sender: TObject);
begin
  Form3.Show;
end;

解决方案 »

  1.   

    参考
    动态创建菜单全接触
                 高红岩 
    基本认识:
    在Delphi的程序开发环境中,封装的VCL减化了我们许多的开发工作,由在界面的设计上使开发的进度很快,但在很多的时候,我们需要自己来设计可视化的用户界面,而且是在程序的运行中,这时我们就得利用Delphi给我们提供的类来完成我们需要的工作了,下面笔者就和朋友们浅入的讨论一下动态创建"菜单"的基本知识,希望本文给那些刚入门的朋友来个抛砖引玉的作用。
    在delphi的菜单设计中,有两个Delphi的菜单控件:
    1:Tmainmenu;
    2:Tpopupmenu;
    前者是创建窗口的菜单,后者是创建右键弹出式菜单的控件,但在Delphi庞大的类库中有一个类与这两个控件密切相关,它就是:TMenuItem,窗口的菜单和右键弹出式菜单的每个条目都是TMenuItem类的一个对象。此TMenuItem类不出现在控件板上,在程序中用代码可创建其实例。 
    基本知识:
    在tmainmenu,tpopupmenu控件中有一个属性是items,此属性是数组型,里面的参数为菜单项的索引值。
    文件 编辑 查看 插入 格式 帮助
    ---- ---- ---- ---- ---- ----
    新建 撤消 标尺 对象 字体 关于
    打开 拷贝 源码 公式 颜色 相信您看过上面的菜单简单表示之后是非常熟悉的,在此菜单中菜单头的索引值代表如下:
    "文件"的菜单的items值为0;
    "编辑"的菜单的items值为1;以此类推。
    items属性是tmenuitem类型,而在此类型中还有一个属性,是items,如果您略懂"类"的关系,您就不难明白此类似"嵌套"的关系。"新建"菜单选项是"文件"菜单选项的子类,用代码表示为tmainmenu.items[0].items[0],"打开"菜单选项为tmainmenu.items[0].items[1],以此类推,而代表"编辑"菜单中的"拷贝"菜单选项的代码为tmainmenu.items[1].items[1],其它菜单代码表示以此类推。
    基本实例:
    知道了菜单的items结构之后,我们就可以进一步大胆的创建自己有序的菜单了。
    上面讨论到窗口的菜单和右键弹出式菜单的每个条目都是TMenuItem类的一个对象。那么我们就可以create它的一个实例,来添加自己想要的菜单了。
    示例过程:
    1:新建一个工程。
    2:添加一个tmainmenu控件。
    3:添加一个button控件,并在button的onclick事件中写入如下代码:
    procedure TForm1.Button1Click(Sender: TObject);
    var
    files,edit:tmenuitem;{要有实例的声明}
    begin
    files:=tmenuitem.Create(self);
    edit:=tmenuitem.create(self);
    files.Caption:='文件';
    edit.caption:='编辑';
    mainmenu1.AutoHotkeys:=mamanual;{此句代码为不让系统自动设置快捷键}
    form1.MainMenu1.Items.Add(files);
    form1.mainmenu1.items.add(edit);
    end;  
    运行后,出现如上面例举的菜单的部分结构,如此看来动态创建菜单项的方法是非常简单的,这无疑于Delphi把系统的函数进行了封装。菜单头我们创建完了,接下来就该创建菜单里的菜单项了,由"items属性是tmenuitem类型,而在此类型中还有一个属性,是items"此句话的意思我们可以创建菜单项,代码如下:
    1:新建一个工程。
    2:添加一个tmainmenu控件。 
    3:添加一个button控件,并在button的onclick事件中写入如下代码:
    procedure TForm1.Button1Click(Sender: TObject);
    var
    files,edit:tmenuitem;
    new,copy:tmenuitem;
    begin
    files:=tmenuitem.Create(self);
    edit:=tmenuitem.create(self);
    files.Caption:='文件';
    edit.caption:='编辑';
    mainmenu1.AutoHotkeys:=mamanual;{此句代码为不让系统自动设置快捷键}
    form1.MainMenu1.Items.Add(files);
    form1.mainmenu1.items.add(edit);
    {上部代码为创建菜单头}
    new:=tmenuitem.create(self);
    copy:=tmenuitem.create(self);
    new.Caption:='新建';
    copy.caption:='拷贝';
    files.Add(new);
    edit.add(copy);
    {上部代码为创建菜单项}
    end; 
    运行效果和上面菜单结构表中基本一样,但此时点击菜单项时不出现任何的事件,显然这样的软件出售量不算理想,我们可以略改代码加个事件上去。
    代码如下:
    1:新建一个工程。
    2:添加一个tmainmenu控件。
    3:
    private
    procedure abc(sender:tobject);
    { Private declarations }
    var
    Form1: TForm1;implementation{$R *.DFM}procedure tform1.abc(sender:tobject);
    begin
    showmessage('welcome you click me!! :) xixi');
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    var
    files,edit:tmenuitem;
    new,copy:tmenuitem;
    begin
    files:=tmenuitem.Create(self);
    edit:=tmenuitem.create(self);
    files.Caption:='文件';
    edit.caption:='编辑';
    mainmenu1.AutoHotkeys:=mamanual;{此句代码为不让系统自动设置快捷键}
    form1.MainMenu1.Items.Add(files);
    form1.mainmenu1.items.add(edit);
    {上部代码为创建菜单头}
    new:=tmenuitem.create(self);
    copy:=tmenuitem.create(self);
    new.Caption:='新建';
    copy.caption:='拷贝';
    copy.onClick:=abc;
    new.onClick:=abc;
    files.Add(new);
    edit.add(copy);
    {上部代码为创建菜单项}
    end;
    这时这个软件就有了交互的功能。
    有时菜单项中出现一个横的条线和出现一个子的菜单,那么这样的效果怎么用代码实现的呢,下面就是此效果的代码示例:
    1:新建一个工程。
    2:添加一个tmainmenu控件。
    3:
    procedure TForm1.Button1Click(Sender: TObject);
    var
    files,edit:tmenuitem;
    new,copy:tmenuitem;
    sub1,sub2,sub3,lines:tmenuitem;
    begin
    files:=tmenuitem.Create(self);
    edit:=tmenuitem.create(self);
    files.Caption:='文件';
    edit.caption:='编辑';
    mainmenu1.AutoHotkeys:=mamanual;{此句代码为不让系统自动设置快捷键}
    form1.MainMenu1.Items.Add(files);
    form1.mainmenu1.items.add(edit);
    {上部代码为创建菜单头}
    new:=tmenuitem.create(self);
    copy:=tmenuitem.create(self);
    new.Caption:='新建';
    copy.caption:='拷贝';
    files.Add(new);
    edit.add(copy);
    {上部代码为创建菜单项}
    sub1:=tmenuitem.create(self);
    sub2:=tmenuitem.create(self);
    sub3:=tmenuitem.create(self);
    lines:=tmenuitem.create(self);
    lines.caption:='-';
    sub1.caption:='子菜单1';
    sub2.caption:='子菜单2';
    sub3.caption:='子菜单3';
    new.Add(sub1);
    new.add(lines);
    new.add(sub3);
    copy.Add(sub2);
    {上面代码出现多项子菜单和横线的效果}
    end;
      

  2.   

    type
      TNotifyEvent = procedure (Sender:TObject) of Object;
       .
       .
       .
    var 
      OnClick :TNotifyEvent;procedure CreateMenuItem
    var sMethodName :string;
    begin
        .
        .
        .
         sMethodName :=Query.FielByName('Event').AsString;
         
         OnClick :=...    //如何将sMethodName转成事件
         MenuItem.OnClick :=OnClick;
        .
        .
        .
    end
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, 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);
        procedure show(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;
      y:integer;
      
    implementation{$R *.dfm}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+1)+')';
        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]);
    //调用mypopuphandler事件
        mysubitems[i].OnClick:=mypopuphandler;
      end;
    //第二个菜单设为分隔符
      mysubitems[1].Caption :='-';
    //第三个菜单设置竖向分隔条
      mysubitems[3].Break :=mbbarbreak;
    end;
    procedure tform1.mypopuphandler(sender:tobject);
    begin
      with sender as tmenuitem do
        begin
          showmessage(caption);
        end;
    end;
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      y:=1;
      mypopupmenu:=tpopupmenu.create(self);
    //创建弹出式菜单
      for i:=0 to 3 do begin
        mypopupitems[i]:=tmenuitem.Create(self);
        mypopupitems[i].Caption :='弹出式菜单项'+inttostr(i)+'(&'+inttostr(i+1)+')';
        mypopupmenu.items.add(mypopupitems[i]);
        mypopupitems[i].OnClick :=mypopuphandler;
      end;
    end;procedure TForm1.Button3Click(Sender: TObject);
    begin
    if y=0 then exit;
    //定点击活popupmenu
    mypopupmenu.popup(form1.Left +60,form1.Top +60);
    end;procedure TForm1.show(Sender: TObject);
    begin
    y:=0;
    end;end.
      

  4.   

    procedure CreateMenuItem
    var sMethodName :string;
    begin
        .
         sMethodName :=Query.FielByName('Event').AsString;
         
         MenuItem.action := TAction(findcomponent(smethodName));    
        .
    end
      

  5.   

    或者用
    procedure CreateMenuItem
    var sMethodName :string;
    begin
        .
        .
        .
         sMethodName :=Query.FielByName('Event').AsString;
         
         OnClick := TBasicAciton(FindComponent(SmethodName)).onexecute;
                            //如何将sMethodName转成事件
         MenuItem.OnClick :=OnClick;
        .
        .
        .
    end-----------------------------------
    这样楼主唯一需要变动的是将处理过程定义为Action;而不能定义为onclick;^_^
      

  6.   

    To 47522341
      sMethodName :=Query.FielByName('Event').AsString;
      OnClick :=MethodAddress(sMethodName)//为什么不能将事件的地址赋给OnClick事件
      

  7.   

    现已自己解决了,将代码公布出来:
    type
      TNotifyEvent = procedure (Sender:TObject) of Object;
      TForm1 = class(TForm)
        Button1: TButton;
        ADOConnection1: TADOConnection;
        Q_MenuItem: TADOQuery;
        procedure FormCreate(Sender: TObject);
        procedure NewForm2(Sender :TObject);
        procedure NewForm3(Sender :TObject);
      private
        { Private declarations }
        procedure CreateMainMenu;
        procedure GetMenuItemData(RootID :Integer);
        procedure GetHeadItemData;
        procedure CreateMenuItem(RootID :Integer);
        procedure AddMenuItem(RootID,ParentID :Integer);
        function FindItem(RootID,ID:Integer):TMenuItem;
      public
        { Public declarations }
      published
        { published declarations }  end;
    var
      Form1: TForm1;
      OnClick :TNotifyEvent;implementationuses Unit2, Unit3;procedure TForm1.FormCreate(Sender: TObject);
    begin
      CreateMainMenu;
    end;procedure ExecSQL(Sender:TADOQuery; sSQL :string);
    begin
      with Sender do
        begin
          Active :=False;
          SQL.Clear;
          SQL.Add(sSQL);
          Active :=True;
        end;
    end;procedure TForm1.GetMenuItemData(RootID: integer);
    var sSQL :string;
    begin
      sSQL :='Select ID,ItemName,ItemCaption, ItemOrder,ImageIndex,ParentID,RootID,Tag,IsCheck,IsEnable,IsVisible,ShortCut,ClickEvent From SR_SYS_MAINMENU Where '+
          'IsRoot=0 and RootID='''+IntToStr(RootID)+''' Order by ItemOrder ';
      ExecSQL(Form1.Q_MenuItem,sSQL);
    end;procedure TForm1.GetHeadItemData;
    var sSQL :string;
    begin
      sSQL :='Select ID,ItemName,ItemCaption, ItemOrder,ImageIndex,Tag,IsCheck,IsEnable,IsVisible,ShortCut,ClickEvent From SR_SYS_MAINMENU Where '+
          'IsRoot=1  Order by ItemOrder ';
      ExecSQL(Form1.Q_MenuItem,sSQL);
    end;procedure TForm1.CreateMainMenu;
    var MainMenu: TMainMenu;
        MenuItem :Array of TMenuItem;
        i,HeadCount :integer;
    begin
       MainMenu:= TMainMenu.Create(Self);
       MainMenu.AutoHotkeys :=maManual;
       MainMenu.AutoLineReduction :=maManual;
       // Create HeadMenu
      GetHeadItemData;
      HeadCount :=Q_MenuItem.RecordCount;
      SetLength(MenuItem,HeadCount);
      for i :=0 to HeadCount-1 do
        begin
          MenuItem[i] :=TMenuItem.Create(Self);
          MenuItem[i].Name := Trim(Q_MenuItem.FieldByName('ItemName').AsString);
          MenuItem[i].Caption := Trim(Q_MenuItem.FieldByName('ItemCaption').AsString);
          MenuItem[i].ImageIndex :=Q_MenuItem.FieldByName('ImageIndex').AsInteger;
          MenuItem[i].Tag:=StrToInt(Trim(Q_MenuItem.FieldByName('Tag').AsString));
          MenuItem[i].Checked :=StrToBool(Q_MenuItem.FieldByName('IsCheck').AsString);
          MenuItem[i].Enabled :=StrToBool(Q_MenuItem.FieldByName('IsEnable').AsString);
          MenuItem[i].Visible :=StrToBool(Q_MenuItem.FieldByName('IsVisible').AsString);
          MenuItem[i].ShortCut :=TextToShortCut(Trim(Q_MenuItem.FieldByName('IsVisible').AsString));
          MainMenu.Items.Add(MenuItem[i]);
          Q_MenuItem.Next;
        end;
      //Create MenuItem
      for i :=0 to HeadCount-1 do
        CreateMenuItem(i);end;procedure TForm1.CreateMenuItem(RootID: Integer);
    var MenuItem :TMenuItem;
        i,ItemCount,ParentID :integer;
    begin
      GetMenuItemData(RootID);
      ItemCount :=Q_MenuItem.RecordCount;
      for i :=0 to ItemCount-1 do
        begin
          ParentID :=Q_MenuItem.FieldByName('ParentID').AsInteger;
          MenuItem :=TMenuItem.Create(Self);
          AddMenuItem(RootID,ParentID);
          Q_MenuItem.Next;
        end;
    end;procedure TForm1.AddMenuItem(RootID,ParentID :Integer);
    var ParentItem,MenuItem :TMenuItem;
        SmethodName :string;
    begin
      ParentItem :=FindItem(RootID,ParentID);
      if ParentItem <> nil then
        begin
          MenuItem :=TMenuItem.Create(Self);
          MenuItem.Name := Trim(Q_MenuItem.FieldByName('ItemName').AsString);
          MenuItem.Caption := Trim(Q_MenuItem.FieldByName('ItemCaption').AsString);
          MenuItem.ImageIndex :=Q_MenuItem.FieldByName('ImageIndex').AsInteger;
          MenuItem.Tag:=StrToInt(Trim(Q_MenuItem.FieldByName('Tag').AsString));
          MenuItem.Checked :=StrToBool(Q_MenuItem.FieldByName('IsCheck').AsString);
          MenuItem.Enabled :=StrToBool(Q_MenuItem.FieldByName('IsEnable').AsString);
          MenuItem.Visible :=StrToBool(Q_MenuItem.FieldByName('IsVisible').AsString);
          MenuItem.ShortCut :=TextToShortCut(Trim(Q_MenuItem.FieldByName('IsVisible').AsString));
          sMethodName:=Trim(Q_MenuItem.FieldByName('ClickEvent').AsString);
          
          if sMethodName<>'' then
            begin
              @OnClick :=MethodAddress(SmethodName);
              if @OnClick<>nil then
                MenuItem.OnClick :=OnClick;
            end;      ParentItem.Add(MenuItem);    end
      else
        begin    end;
    end;function TForm1.FindItem(RootID, ID: Integer):TMenuItem;
    var j :Integer;
        sSQL :string;
        Query: TADOQuery;
    begin
      Query :=TADOQuery.Create(Self);
      sSQL :='Select ID,ItemName,ItemCaption, ItemOrder,ImageIndex,ParentID,RootID,Tag,IsCheck,IsEnable,IsVisible,ShortCut,ClickEvent From SR_SYS_MAINMENU Where '+
          ' RootID='''+IntToStr(RootID)+''' and ID='''+IntTostr(ID)+''' Order by ItemOrder ';
      Query.Connection :=ADOConnection1;
      ExecSQL(Query,sSQL);
      Result :=nil;  if Query.RecordCount=1 then
        begin
          for j := 0 to ComponentCount - 1 do
            if Components[j] is TMenuItem then
              if UpperCase(Components[j].Name)=UpperCase(Trim(Query.FieldByName('ItemName').AsString)) then
              begin
                Result := TMenuItem(Components[j]);
                Break;
              end;
        end;
    end;procedure TForm1.NewForm2(Sender: TObject);
    begin
      Form2.Show;
    end;procedure TForm1.NewForm3(Sender: TObject);
    begin
      Form3.Show;
    end;