?
Solved

Dynamic Menus in Delphi 6

Posted on 2003-03-23
5
Medium Priority
?
295 Views
Last Modified: 2010-05-18
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
Comment
Question by:miltonrodrigueza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 12

Accepted Solution

by:
esoftbg earned 500 total points
ID: 8190669
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
 

Assisted Solution

by:JAPerrett
JAPerrett earned 500 total points
ID: 8226898
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
 

Expert Comment

by:CleanupPing
ID: 9316635
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question