给动态创建的TREE和MAINMENU关联点击事件
使用递归方法遍历MAINMENU的所有菜单项
procedure TFormMain.BLMenu;
procedure GetItems(AItem:TMenuItem);
var
I:integer;
begin
AItem.OnClick := MenuTreeClick; //菜单项关联点击事件
for I:=0 to AItem.Count-1 do begin
GEtItems(AItem.Items[I]);
end;
end;
var
I:integer;
begin
for I:=0 to MainMenu1.Items.Count-1 do begin
GetItems(MainMenu1.Items.Items[I]);
end;
end;
公用的点击事件处理方法
procedure TFormMain.MenuTreeClick(Sender: TObject);
begin
if Sender is TTreeView then // 通过SENDER来判断是点击了菜单项还是树的节点
todo(TTreeView(Sender).Selected.Text)
else if Sender is TMenuItem then
todo(StripHotkey(TMenuItem(Sender).Caption));
end;
公用打开子窗体方法
procedure TFormMain.openForm(AFormClass: TFormClass; var aForm: TForm;
aOwner: TWinControl);
begin
if aOwner = nil then Exit;
if aForm = nil then
aForm := AFormClass.Create(aOwner);
with aForm do
begin
ManualDock(aOwner);
WindowState := wsMaximized;
Align := alClient;
Show;
end;
end;
点击事件的处理方法
procedure TFormMain.todo(const aCaption: string);
begin
if Pos('数据字典', acaption) <> 0 then begin
if ActiveExistTabsheet('数据字典') then Exit;
openForm(TformDictionary, tform(formdictionary), GetTabSheet('数据字典'));
end else if Pos('系统菜单', aCaption) <> 0 then begin
if ActiveExistTabsheet('系统菜单') then Exit;
openForm(Tformmenu, tform(formMenu), GetTabSheet('系统菜单'));
end else if Pos('货品类别管理', aCaption) <> 0 then begin
if ActiveExistTabsheet('货品类别管理') then Exit;
openForm(TformCategory, tform(formCategory), GetTabSheet('货品类别管理'));
end else if Pos('操作员管理', aCaption) <> 0 then begin
if ActiveExistTabsheet('操作员管理') then Exit;
openForm(TFormOperator, tform(FormOperator), GetTabSheet('操作员管理'));
end;
end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/archive/2010/08/14/2940683.html