• Delphi遍历MainMenu


    开发环境D7

    获取所有菜单的Caption

     1 unit Unit1;
     2 
     3 interface
     4 
     5 uses
     6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
     7   Dialogs, StdCtrls, Menus;
     8 
     9 type
    10   
    11   TForm1 = class(TForm)
    12     MainMenu1: TMainMenu;
    13     A: TMenuItem;
    14     B: TMenuItem;
    15     C: TMenuItem;
    16     A_1: TMenuItem;
    17     A_1_1: TMenuItem;
    18     A_1_2: TMenuItem;
    19     A_2: TMenuItem;
    20     B_1: TMenuItem;
    21     B_2: TMenuItem;
    22     C_1: TMenuItem;
    23     C_2: TMenuItem;
    24     C_2_1: TMenuItem;
    25     Memo1: TMemo;
    26     Button1: TButton;
    27     procedure Button1Click(Sender: TObject);
    28   private
    29     procedure MainMenuAddMemo(sMenuItem:TMenuItem);
    30     { Private declarations }
    31   public
    32     { Public declarations }
    33   end;
    34 
    35 
    36 
    37 var
    38   Form1: TForm1;
    39 
    40 implementation
    41 
    42 {$R *.dfm}
    43 procedure TForm1.Button1Click(Sender: TObject);
    44 var
    45   I:Integer;
    46 begin
    47   if MainMenu1.Items.Count >0 then
    48   begin
    49     Memo1.Clear;
    50     for i:=0 to MainMenu1.Items.Count-1 do
    51     begin
    52       MainMenuAddMemo(MainMenu1.Items[i]);
    53     end;
    54   end;
    55 end;
    56 
    57 procedure TForm1.MainMenuAddMemo(sMenuItem: TMenuItem);
    58 var
    59   i:integer;
    60 begin
    61   Memo1.Lines.Add(sMenuItem.Caption);
    62   if sMenuItem.Count>0 then
    63   begin
    64     for i:=0 to sMenuItem.Count-1 do
    65     begin
    66       if sMenuItem.Items[i].Count>0 then
    67       begin
    68         MainMenuAddMemo(sMenuItem.Items[i]);
    69       end
    70       else
    71         Memo1.Lines.Add(sMenuItem.Items[i].Caption);
    72     end;
    73   end;
    74 end;
    75 
    76 end.
     1 object Form1: TForm1
     2   Left = 654
     3   Top = 247
     4   Width = 295
     5   Height = 539
     6   Caption = 'Form1'
     7   Color = clBtnFace
     8   Font.Charset = DEFAULT_CHARSET
     9   Font.Color = clWindowText
    10   Font.Height = -11
    11   Font.Name = 'MS Sans Serif'
    12   Font.Style = []
    13   Menu = MainMenu1
    14   OldCreateOrder = False
    15   PixelsPerInch = 96
    16   TextHeight = 13
    17   object Memo1: TMemo
    18     Left = 0
    19     Top = 0
    20     Width = 185
    21     Height = 473
    22     ImeName = '中文(简体) - 搜狗拼音输入法'
    23     Lines.Strings = (
    24       'Memo1')
    25     ScrollBars = ssBoth
    26     TabOrder = 0
    27   end
    28   object Button1: TButton
    29     Left = 192
    30     Top = 160
    31     Width = 75
    32     Height = 25
    33     Caption = 'Button1'
    34     TabOrder = 1
    35     OnClick = Button1Click
    36   end
    37   object MainMenu1: TMainMenu
    38     AutoHotkeys = maManual
    39     Left = 112
    40     Top = 24
    41     object A: TMenuItem
    42       Caption = 'A'
    43       object A_1: TMenuItem
    44         Caption = 'A_1'
    45         object A_1_1: TMenuItem
    46           Caption = 'A_1_1'
    47         end
    48         object A_1_2: TMenuItem
    49           Caption = 'A_1_2'
    50         end
    51       end
    52       object A_2: TMenuItem
    53         Caption = 'A_2'
    54       end
    55     end
    56     object B: TMenuItem
    57       Caption = 'B'
    58       object B_1: TMenuItem
    59         Caption = 'B_1'
    60       end
    61       object B_2: TMenuItem
    62         Caption = 'B_2'
    63       end
    64     end
    65     object C: TMenuItem
    66       Caption = 'C'
    67       object C_1: TMenuItem
    68         Caption = 'C_1'
    69       end
    70       object C_2: TMenuItem
    71         Caption = 'C_2'
    72         object C_2_1: TMenuItem
    73           Caption = 'C_2_1'
    74         end
    75       end
    76     end
    77   end
    78 end
  • 相关阅读:
    java处理图片压缩、裁剪
    List按对象元素自定义排序
    List和数组汉字简单排序(转)
    欢迎访问我的个人博客,部分文章迁移
    Java资源免费分享,每日一更新,找到你心仪的吧
    今年的校招,Java好拿offer吗?
    【拥抱大厂系列】几个面试官常问的垃圾回收器,下次面试就拿这篇文章怼回去!
    2019,我的这一年,在校研究生做到年入20W,另送我的读者2000元现金红包
    深入理解Java虚拟机-如何利用VisualVM对高并发项目进行性能分析
    深入理解Java虚拟机-常用vm参数分析
  • 原文地址:https://www.cnblogs.com/dmqhjp/p/15985827.html
Copyright © 2020-2023  润新知