zoukankan      html  css  js  c++  java
  • 给动态创建的TREE和MAINMENU关联点击事件

    使用递归方法遍历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;

  • 相关阅读:
    字符串匹配之朴素匹配
    XSS的攻击原理
    使用metasploit收集邮箱
    C++实现折半插入排序
    C++插入排序实现
    Java中的NIO
    Hashtable和HashMap区别(面试)
    面向对象:封装(一):构造函数;类的主方法;权限修饰符;对象的创建
    switch多分支语句
    递归和字母数字生成随机数
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2940683.html
Copyright © 2011-2022 走看看