Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to disable / enable a menu item depending on the user and his password Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
26-Oct-02
Category
VCL-Menu
Language
Delphi 2.x
Views
194
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I want to enable/ disable the menu items of a TMainMenu according to the user and 
his password. With the property Items I can only reach the subitems of each one of 
the main items. Is it possible to process all the items (independently of its 
parent) by its Name or Tag property?

Answer:

Well, this is basically a lookup task. If all the menu items are created at 
design-time the form will have fields for them and you can find them by name using 
the forms FindComponent method, using the menu items Name property. If you want to 
find items by Tag value you have to iterate either over the menu items 
(recursively) , starting at the forms Menu property, or over the forms Components 
array, looking for components of class TMenuitem.
1   
2   function Tform1.FindMenuItemByTag(atag: Integer): TMenuItem;
3   
4     function FindItems(anItem: TMenuItem; aTag: Integer): TMenuItem;
5     var
6       i: Integer;
7     begin
8       Result := nil;
9       if Assigned(anItem) then
10      begin
11        if anItem.Tag = aTag then
12          Result := anItem
13        else
14        begin
15          for i := 0 to anItem.Count - 1 do
16          begin
17            Result := FindItems(anItem[i], aTag);
18            if Assigned(result) then
19              Break;
20          end;
21        end;
22      end;
23    end;
24  
25  begin
26    if Assigned(Menu) then
27      Result := FindItems(Menu.Items, atag)
28    else
29      Result := nil;
30  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC