200分,得到主菜单控件TMainMenu的个数并对其进行操作(200分)

  • 主题发起人 kingkong
  • 开始时间
K

kingkong

Unregistered / Unconfirmed
GUEST, unregistred user!
我的程序需要遍历控件并得到主菜单TMainMenu的个数并对其进行操作,我试了Controls
和Components两种方法都不成功请大家指教,程序如下:
for I:= 0 to Self.ControlCount - 1 do
begin
if (Self.Components is TMainMenu) then
begin
...............
end;
end;
 
取得MainMenu数量
--------------------------------------------------------------
Function TForm1.GetMainMenu:Integer;
var
I:Integer;
begin
Result:=0;

For I := 0 to Self.ComponentCount - 1 do
begin
if Components is TMainMenu then Result:=Result+1;
end ;
end;
 
ControlCount只能针对继承TWinControl的控件,而MainMenu不是继承TWinControl的
你的这段代码要实现怎么样的功能,看看有没有别的办法实现
 
用上面那个函数肯定没有问题,我试过了(Delphi 6.0)
 
哈哈,只想到ControlCount 不行,忘记了ComponentCount行的
哎真笨
 
谁能帮我解决一下打印机设置问题啊?

急得要命
 
谢谢!给分!!!!!!!
 
给分吧兄弟
假设你的TMainMenu名称为MainMenu1:
MainMenu1.Items.Count 得到主菜单的个数
MainMenu1.Items[n].Count 得到第n个菜单的子菜单个数
 
顶部