| 发表于:2007-01-20 15:57:1611楼 得分:80 |
procedure tform1.button1click(sender: tobject); var vrootitem: tmenuitem; function findmenuitem(aid: string): tmenuitem; var i: integer; vparentitem: tmenuitem; begin result := nil; if aid = ' ' then exit; for i := 0 to mainmenu1.componentcount - 1 do if mainmenu1.components[i] is tmenuitem then begin if sametext(striphotkey(tmenuitem(mainmenu1.components[i]).caption), aid) then begin result := tmenuitem(mainmenu1.components[i]); exit; end; end; result := tmenuitem.create(mainmenu1); result.caption := aid; //result.onclick := menuitemclick; vparentitem := findmenuitem(copy(aid, 1, length(aid) - 2)); if assigned(vparentitem) then vparentitem.add(result) else vrootitem.add(result); end; var s: string; begin vrootitem := mainmenu1.items; adotable1.open; while not adotable1.eof do begin s := adotable1.fieldbyname( 'field1 ').asstring; findmenuitem(s); adotable1.next; end; end; | | |
|