• unigui菜单【3】


    unigui菜单TuniTreeView

    根据数据库表中的内容,显示菜单的处理:

    function TMainForm.CreateMenu: Integer;
    var
      myMenuPoint : PMyMenuRec;
      i :Integer;
      menu_id ,menu_name, menu_url: string;
      mynodes : TUniTreeNodes;
      mynode,tmp_node : TUniTreeNode;
    begin //建立菜单树
      MenuTree.Items.Clear;
      mynodes := MenuTree.Items;
      MenuTree.BeginUpdate;
      with UniMainModule do
        begin //取表中菜单
          fdqryBase.Open('select* from sm_menu order by menu_id');
          fdqryBase.First;
          while not fdqryBase.Eof do
            begin
              menu_id := fdqryBase.FieldByName('menu_id').AsString;
              menu_name := fdqryBase.FieldByName('menu_name').AsString;
              if fdqryBase.FieldByName('menu_url').AsString = '' then
                begin  //确认是否根菜单
                  mynode := mynodes.Add(nil,fdqryBase.FieldByName('menu_name').AsString);
                end else
                begin
    
                  tmp_node := mynodes.add(mynode,menu_name);
                  New(myMenuPoint);
                  myMenuPoint^.menu_id := menu_id;
                  myMenuPoint^.menu_name := menu_name;
                  myMenuPoint^.menu_url := fdqryBase.FieldByName('menu_url').AsString;
                  tmp_node.Data :=  myMenuPoint;
    
                end;
              fdqryBase.Next;
            end;
        end;
      MenuTree.EndUpdate;
    
      for i := 0 to MenuTree.Items.Count-1 do
        begin
          mynode := MenuTree.Items[i];
          if mynode.HasChildren then begin
            mynode.ImageIndex := 0;
            mynode.SelectedIndex := 0;
          end else begin
            mynode.ImageIndex := 2;
            mynode.SelectedIndex := 3;
          end;
      end;
      MenuTree.FullCollapse;
    end;
    View Code

    其中item的node有二个属性caption和data。把指针data用起来,在点击时自动调用显示form。

    type
       PMyMenuRec = ^TMyMenuRec;
       TMyMenuRec = Record
         menu_id:string;
         menu_name:string;
         menu_url:string;
       end;

    点击菜单项的处理

    procedure TMainForm.MenuTreeClick(Sender: TObject);
    begin
      if Assigned(MenuTree.Selected.data) then
         begin
           if PMyMenuRec(MenuTree.Selected.data).menu_url<>'' then
            ShowFrame(PMyMenuRec(MenuTree.Selected.data).menu_name,PMyMenuRec(MenuTree.Selected.data).menu_url);
         end;
    end;
    function TMainForm.ShowFrame(Caption, FormClassName: string): Integer;
    var
    i: integer;
    sheet: TUniTabSheet;
    begin
      for i := 0 to page.PageCount - 1 do
      begin
      if page.Pages[i].Caption = Caption then
        begin
          page.ActivePageIndex := i;
          exit;
        end;
      end;
      sheet := TUniTabSheet.Create(Self);
      sheet.Closable := True;
      sheet.Caption := Caption;
      sheet.PageControl := page;
    
      FCurrentFrame :=  TUniFrameClass(FindClass(FormClassName)).Create(Self);
      FCurrentFrame.Align := alClient;
      FCurrentFrame.Parent := sheet;
      page.ActivePage := sheet;
    
    end;

    表菜单记录。

    10    登记客户信息    NULL
    1001    新客户    TUniFrmeWebEmbedBase
    1002    修改客户    222
    20    客户查询    NULL
    2001    按地区    43
    2002    按行业    3452
    30    客户信息统计    NULL
    40    客户新机报表    NULL

    表结构

    CREATE TABLE [dbo].[SM_menu](
        [menu_id] [nvarchar](32) NOT NULL,
        [menu_name] [nvarchar](30) NULL,
        [menu_url] [nvarchar](50) NULL,
     CONSTRAINT [PK153] PRIMARY KEY CLUSTERED 
    (
        [menu_id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
  • 相关阅读:
    在CentOS-6.3环境下,利用grub工具手工制作Linux U盘安装盘
    Windowns DOS For 循环实例
    Bootstrap 标签的变体 实例样式
    Bootstrap两端对齐的导航实例
    bootstrap 分页样式代码
    C# 微信扫码支付API (微信扫码支付模式二)
    AjaxFileUpload 在C#中应用
    关于百度编辑器UEditor(1.4.3)在C#.NET中的应用实例
    电脑运行状态
    网络测试
  • 原文地址:https://www.cnblogs.com/usegear/p/9415826.html
Copyright © 2020-2023  润新知