标签:asc module fun onclick image 自动调用 eve sed ems
unigui菜单TuniTreeView
根据数据库表中的内容,显示菜单的处理:
function TMainForm.CreateMenu: Integer; var myMenuPoint : PMyMenuRec; i :Integer; menu_id ,menu_name, menu_url: string; mynodes : TUniTreeNodes; mynode,tmp_node : TUniTreeNode; begin //建立菜单树 MenuTree.Items.Clear; mynodes := MenuTree.Items; MenuTree.BeginUpdate; with UniMainModule do begin //取表中菜单 fdqryBase.Open(‘select* from sm_menu order by menu_id‘); fdqryBase.First; while not fdqryBase.Eof do begin menu_id := fdqryBase.FieldByName(‘menu_id‘).AsString; menu_name := fdqryBase.FieldByName(‘menu_name‘).AsString; if fdqryBase.FieldByName(‘menu_url‘).AsString = ‘‘ then begin //确认是否根菜单 mynode := mynodes.Add(nil,fdqryBase.FieldByName(‘menu_name‘).AsString); end else begin tmp_node := mynodes.add(mynode,menu_name); New(myMenuPoint); myMenuPoint^.menu_id := menu_id; myMenuPoint^.menu_name := menu_name; myMenuPoint^.menu_url := fdqryBase.FieldByName(‘menu_url‘).AsString; tmp_node.Data := myMenuPoint; end; fdqryBase.Next; end; end; MenuTree.EndUpdate; for i := 0 to MenuTree.Items.Count-1 do begin mynode := MenuTree.Items[i]; if mynode.HasChildren then begin mynode.ImageIndex := 0; mynode.SelectedIndex := 0; end else begin mynode.ImageIndex := 2; mynode.SelectedIndex := 3; end; end; MenuTree.FullCollapse; end;
其中item的node有二个属性caption和data。把指针data用起来,在点击时自动调用显示form。
type PMyMenuRec = ^TMyMenuRec; TMyMenuRec = Record menu_id:string; menu_name:string; menu_url:string; end;
点击菜单项的处理
procedure TMainForm.MenuTreeClick(Sender: TObject); begin if Assigned(MenuTree.Selected.data) then begin if PMyMenuRec(MenuTree.Selected.data).menu_url<>‘‘ then ShowFrame(PMyMenuRec(MenuTree.Selected.data).menu_name,PMyMenuRec(MenuTree.Selected.data).menu_url); end; end;
标签:asc module fun onclick image 自动调用 eve sed ems
原文地址:https://www.cnblogs.com/usegear/p/9415826.html