博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
给动态创建的TREE和MAINMENU关联点击事件
阅读量:7085 次
发布时间:2019-06-28

本文共 1586 字,大约阅读时间需要 5 分钟。

使用递归方法遍历MAINMENU的所有菜单项

procedure   TFormMain.BLMenu;

    procedure   GetItems(AItem:TMenuItem);
    var
        I:integer;
    begin
        AItem.OnClick := MenuTreeClick;      //菜单项关联点击事件
        for   I:=0   to   AItem.Count-1   do   begin
            GEtItems(AItem.Items[I]);
        end;
    end;
var
    I:integer;
begin
    for   I:=0   to   MainMenu1.Items.Count-1   do   begin
        GetItems(MainMenu1.Items.Items[I]);
    end;
end;

 

公用的点击事件处理方法

procedure TFormMain.MenuTreeClick(Sender: TObject);

begin
  if Sender is TTreeView then     // 通过SENDER来判断是点击了菜单项还是树的节点
    todo(TTreeView(Sender).Selected.Text)
  else if Sender is TMenuItem then
    todo(StripHotkey(TMenuItem(Sender).Caption));
end;

 

公用打开子窗体方法

procedure TFormMain.openForm(AFormClass: TFormClass; var aForm: TForm;

  aOwner: TWinControl);
begin
  if aOwner = nil then Exit;
  if aForm = nil then
    aForm := AFormClass.Create(aOwner);
  with aForm do
  begin
    ManualDock(aOwner);
    WindowState := wsMaximized;
    Align := alClient;
    Show;
  end;
end;

 

点击事件的处理方法

procedure TFormMain.todo(const aCaption: string);

begin
  if Pos('数据字典', acaption) <> 0 then begin
    if ActiveExistTabsheet('数据字典') then Exit;
    openForm(TformDictionary, tform(formdictionary), GetTabSheet('数据字典'));
  end else if Pos('系统菜单', aCaption) <> 0 then begin
    if ActiveExistTabsheet('系统菜单') then Exit;
    openForm(Tformmenu, tform(formMenu), GetTabSheet('系统菜单'));
  end else if Pos('货品类别管理', aCaption) <> 0 then begin
    if ActiveExistTabsheet('货品类别管理') then Exit;
    openForm(TformCategory, tform(formCategory), GetTabSheet('货品类别管理'));
  end else if Pos('操作员管理', aCaption) <> 0 then begin
    if ActiveExistTabsheet('操作员管理') then Exit;
    openForm(TFormOperator, tform(FormOperator), GetTabSheet('操作员管理'));
  end;                     
end;

转载地址:http://osgml.baihongyu.com/

你可能感兴趣的文章
Winmail + Rsync + Nmap 实现 Winmail 邮件系统双机热备
查看>>
python读写文件
查看>>
1-4常用路由协议的梳理
查看>>
Javascript核心
查看>>
利用UltraISO制作RedhatU盘启动盘
查看>>
一分钟教你快速建立起MySQL/Mariadb 主从状态检测脚本(shell)
查看>>
hive函数 -- regexp_extract
查看>>
C# vs2010 调用webservice
查看>>
Samba用户管理机制
查看>>
解决securecrt连接centos使用VIM编辑中文时乱码
查看>>
Windows server 2008R2域的安装和访问
查看>>
spring boot简单实现rest服务
查看>>
linux内核编译安装
查看>>
在CentOS/RHEL/Scientific Linux 6 & 7 上安装Telnet
查看>>
linux中hash命令:显示、添加或清除哈希表
查看>>
理解MySQL复制(Replication)——经典文献
查看>>
安卓手机recovery下刷补丁提示:“can't open /sdcard/update.zip(bad)”
查看>>
shared_ptr源码分析
查看>>
AOJ 2164 Revenge of the Round Table 题解《挑战程序设计竞赛》
查看>>
What's new in JSF 2.2
查看>>