Dynamic menu demo

Source: Internet
Author: User

// Dynamic menu demo

Procedure drawmenu (mainmenu: tmainmenu );
Procedure drawsubmenu (pitem: tmenuitem; IID: integer );
VaR
Sqlstr: string;
Item: tmenuitem;
Adomenu: tadoquery;
Begin
Adomenu: = tadoquery. Create (NiL );
Adomenu. Connection: = dataconn. adoconn;
Sqlstr: = 'select fmoduleid, fpmoduleid, ffilename, ftitle, fissubmain, bishide'
+ 'From menumodules'
+ 'Where fpmoduleid = '+ inttostr (IID)
+ 'Order by fseqid ';
If adomenu. Active then adomenu. close;
Adomenu. SQL. Clear;
Adomenu. SQL. Add (sqlstr );
Adomenu. open;
If not adomenu. isempty then
Begin
While not adomenu. EOF do
Begin
If not adomenu. fieldbyname ('bishide '). asboolean then
Begin
Item: = tmenuitem. Create (NiL );
Item. Hint: = adomenu. fieldbyname ('ffilename'). asstring;
// Item. helpcontext
Item. Caption: = adomenu. fieldbyname ('ftitle'). asstring;
Pitem. Add (item );
If adomenu. fieldbyname ('fissubmain'). asboolean then
Drawsubmenu (item, adomenu. fieldbyname ('fleleid'). asinteger)
Else
Begin
Item. Enabled: = false;
Item. onclick: = domenuitem;
End;
End;
Adomenu. Next;
End;
End;
Adomenu. close;
Freeandnil (adomenu );
End;
VaR
Item: tmenuitem;
Sqlstr: string;
Begin
Item: = mainmenu. items;
For icol: = item. Count-1 downto 1 do // unused Index = 1 menuitem and last name hint is help menuitem
Begin
If uppercase (item [icol]. Hint) = 'help' then continue;
Item. Delete (icol );
End;
Sqlstr: = 'select fmoduleid, fpmoduleid, ffilename, ftitle, fissubmain, bishide'
+ 'From menumodules'
+ 'Where fpmoduleid not in (select fmoduleid from menumodules )'
+ 'Order by fseqid ';

If adoquery. Active then adoquery. close;
Adoquery. SQL. Clear;
Adoquery. SQL. Add (sqlstr );
Adoquery. open;
If not adoquery. isempty then
Begin
While not adoquery. EOF do
Begin
If not adoquery. fieldbyname ('bishide '). asboolean then
Begin
Item: = tmenuitem. Create (NiL );
Item. Hint: = adoquery. fieldbyname ('ffilename'). asstring;
// Item. helpcontext
Item. Caption: = adoquery. fieldbyname ('ftitle'). asstring;
Mainmenu. Items. insert (mainmenu. Items. Count-1, item );
If adoquery. fieldbyname ('fissubmain'). asboolean then
Drawsubmenu (item, adoquery. fieldbyname ('fleleid'). asinteger)
Else
Begin
Item. Enabled: = false;
Item. onclick: = domenuitem;
End;
End;
Adoquery. Next;
End;
End;
Adoquery. close;
End;

Procedure setallowmenuitem;
Procedure setitemproperty (item: tmenuitem );
VaR
Icol: integer;
Begin
If item. Count> 0 then
Begin
For icol: = 0 to item. Count-1 do
Begin
Setitemproperty (item [icol]);
End;
End else
Item. Enabled: = // get from item Property
End;
VaR
Item: tmenuitem;
Icol: integer;
Begin
Item: = mainmenu. items;
For icol: = 1 to item. Count-1 do // unused Index = 1 menuitem and last name hint is help menuitem
Begin
If uppercase (item [icol]. Hint) = 'help' then continue;
If item [icol]. Count> 0 then
Setitemproperty (item [icol])
Else
Item [icol]. Enabled: = // get from item Property
End;
End;

Procedure disablemenu;
Procedure setitemdisable (item: tmenuitem );
VaR
Icol: integer;
Begin
If item. Count> 0 then
Begin
For icol: = 0 to item. Count-1 do
Begin
Setitemdisable (item [icol]);
End;
End else
Item. Enabled: = false;
End;
VaR
Item: tmenuitem;
Icol: integer;
Begin
Item: = mainmenu. items;
For icol: = 1 to item. Count-1 do // unused Index = 1 menuitem and last name hint is help menuitem
Begin
If uppercase (item [icol]. Hint) = 'help' then continue;
If item [icol]. Count> 0 then
Setitemdisable (item [icol])
Else
Item [icol]. Enabled: = false;
End;
End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.