1、如何得到TMainMenu最大的子菜单级别数2、已知一菜单项的名称 'mmExample' 字符类型,如何快速定位并得到对应的 TMenuItem拜托了,谢谢!
解决方案 »
- 支持bdmh任大版主
- 我有一个delphi群,群号是6839549欢迎大家进来讨论啊
- 如何合并查询结果使其以一个Dataset集出现?
- 求一个sql的查询语句!~进来看一下吧,谢谢
- 今天是偶生日,特來此散分.....
- 如何使窗体永远前置 如何知道我用CreateProcess起动程序用了多少内存?
- 这个问题,大家来抢呀。100分呀。
- 我创建了一个进程内的com+服务组件,事件始终激活不了???急急急(在线等待...)
- 打印DBGrid表格的标题问题!
- 一个Delphi+MSSQL7的开发问题。。。给最高分了。。。
- 谁能提供一份将*.emf图形格式文件转成*.tiff的源码或者控件?(解决立即放分100!!!)
- 一个字段的多列显示
2.function Find(ACaption: string): TMenuItem;
var
o: TComponent;
i, j: Integer;
maxLevel: Integer;
begin
maxLevel := 0;
for i := 0 to ComponentCount - 1 do
if Components[i] is TMenuItem then begin
o := Components[i];
j := 0;
while TMenuItem(o).Parent <> nil do begin
o := TMenuItem(o).Parent;
Inc(j);
end;
if j > maxLevel then maxLevel := j;
end;
ShowMessage(IntToStr(maxLevel)); o := FindComponent('mmExample');
if o is TMenuItem then
ShowMessage((o as TMenuItem).Caption);
end;
如果是Name,则用上面的FindComponent;
如果是Caption,则:
for i := 0 to ComponentCount - 1 do
if Components[i] is TMenuItem then
if (Components[i] as TMenuItem).Caption = 'mmExample' then
...
Locates a menu item in the Items property array given its caption.function Find(ACaption: string): TMenuItem;DescriptionUse Find to locate the menu item in the Items property array with the caption specified by the ACaption parameter. Find ignores accelerator characters when comparing item captions to the ACaption parameter.Find returns the first menu item in the Items property array with the specified caption, or, if no item is found, nil.
var
mi:tmenuitem;
i, j: Integer;
maxLevel: Integer;
...
maxLevel:=0;
for I := 0 to MenuItem1.Count-1 do
begin
mi:=MenuItem1.Items[I];
while mi.parent<>nil do
begin
mi:=mi.parent;
inc(j);
end;
maxLevel:=max(maxLevel,j);
end;