//动态创建四级菜单
var
MainMenu:TMainMenu;
SubMenu,SubMenu2,submenu3,submenu4:TMenuItem;
MainMenu:=TMainMenu.Create(self);
MainMenu.AutoHotkeys:=maManual;
SubMenu:=TMenuItem.Create(self);
SubMenu.Caption:='一级菜单';
MainMenu.Items.Add(SubMenu);
SubMenu2:=TMenuItem.Create(self);
SubMenu2.Caption:='二级菜单';
SubMenu.Add(SubMenu2);
submenu3:=TMenuItem.Create(self);
submenu3.Caption:='三级菜单';
submenu2.Add(submenu3);
submenu4:=TMenuItem.Create(self);
submenu4.Caption:='四级菜单';
submenu3.Add(submenu4);
//动态给四级菜单关联事件
procedure LinkEvent;
var
i,j,k,l,t:Integer;
begin
for i:=0 to MainMenu.Items.Count-1 do
begin
for t:=Low(ss) to High(ss) do
if MainMenu.Items[i].Caption=ss[t] then
MainMenu.Items[i].OnClick:=MenuItemClick;
for j:=0 to MainMenu.Items[i].Count-1 do
begin
for t:=Low(ss) to High(ss) do
if MainMenu.Items[i].Items[j].Caption=ss[t] then
MainMenu.Items[i].Items[j].OnClick:=MenuItemClick;
for k:=0 to MainMenu.Items[i].Items[j].Count-1 do
begin
for t:=Low(ss) to High(ss) do
if MainMenu.Items[i].Items[j].Items[k].Caption=ss[t] then
MainMenu.Items[i].Items[j].Items[k].OnClick:=MenuItemClick;
for l:=0 to MainMenu.Items[i].Items[j].Items[k].Count-1 do
for t:=Low(ss) to High(ss) do
if MainMenu.Items[i].Items[j].Items[k].Items[l].Caption=ss[t] then
MainMenu.Items[i].Items[j].Items[k].Items[l].OnClick:=MenuItemClick;
end;
end;
end;
end;
//动态菜单数据表设计
菜单树
层次序列号 功能编号 功能名称 标识 是否激活