码农的笔记

Delphi虽好,但已不流行; 博客真好,可以做笔记

博客园 首页 新随笔 联系 订阅 管理

开发环境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

 

posted on 2022-03-09 16:36  码农的笔记  阅读(213)  评论(0编辑  收藏  举报