• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Dynamic Menus in Delphi 6

Hiya,

Im having a bit of a problem with a project in Delphi 6.
Basically what I need to do is to toggle visible/invisible some menu options in my application.

a short sample of what Ive done so far (in the show event of my main form):

if vshowoption = False then
       mmMain.Items.Find('MyOption').Visible := False;

where:

vshowoption is a boolean variable that is read from an .Ini file
mmMain is the main menu of my application
'MyOption' is the caption of the menu option I want to make invisible

unfortunatly when executed, the application is displaying the following error message:

Project Pfsclient.exe raised exception class EAccessViolation with message 'Access Violation at address 00468D57in module 'pfsclient.exe'. read of address 00000039'. Process stopped. Use Step or Run to continue.

Any suggestions on how to sort this problem are most wellcome.

Thanks.

Milton
0
miltonrodrigueza
Asked:
miltonrodrigueza
2 Solutions
 
esoftbgCommented:
var
  I:      Integer;
begin
  for I := 0 to ComponentCount-1 do
  begin
    if (Components[I].ClassType=TMenuItem) then
      if ((Components[I] as TMenuItem).Caption='MyOption') then
        (Components[I] as TMenuItem).Visible := vshowoption;
  end;
end;
0
 
JAPerrettCommented:
I think this shows where you went wrong with your version

this toggles on and off the 'fred' menuitem when called


procedure findmenuitem;
var tm:TMenuitem;
x:integer;
begin
  x:=0;
  tm:=nil;
  while (x< form1.mainmenu1.items.count) and (tm=nil) do
      begin
        tm:=form1.mainmenu1.items[x].Find('fred');
        inc(x);
      end;
    if tm<>nil then tm.Visible := not tm.Visible;
end;
0
 
CleanupPingCommented:
miltonrodrigueza:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now