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
Solved

Menuitems dissapear

Posted on 2004-10-07
18
338 Views
Last Modified: 2008-01-09
I am building an application and it now consists of 1 main form with a couple of buttons leading to other forms.
Every form has a ActionMainMenuBar, and only the main form has a ActionManager. So, ever ActionMainMenuBar is linked to this ActionManager.

When i press a button a new form is created and shown:

procedure Thoofdscherm.overzichtBtnClick(Sender: TObject);
begin
  overzichtenMenu := ToverzichtenMenu.Create(hoofdmenu.hoofdscherm);
  try
    overzichtenMenu.ShowModal;
  finally
    overzichtenMenu.Release;
  end;
end;

When this new form is shown, everything works fine.
BUT
When i close it, and again reopen it the ActionMainMenuBar is suddenly empty, all the items on it are gone.

Thanks for any help.
0
Comment
Question by:Joeri_
  • 10
  • 7
18 Comments
 
LVL 3

Expert Comment

by:Sabre
ID: 12246788
I am not 100% sure what you are doing in your code as my main and only language is English, however, it may be that the ActionMainMenuBar you mention is freed with the form (if it is made the parent of the ActionMainMenuBar).
0
 

Author Comment

by:Joeri_
ID: 12246834
Ah, those strange words are just names for forms

hoofdscherm is the mainform
overzichtenMenu is the form that is made by pushing a button on the main form.

That could be the problem, what you said. Is there an easy way to fill the mainmenubar when the form is created, so i can test it ?
0
 
LVL 3

Expert Comment

by:Sabre
ID: 12246858
I don't have delphi to hand at the moment but try http://www.lmc-mediaagentur.de/dpool/inter07.htm - there are some tips there that may help.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 3

Expert Comment

by:Sabre
ID: 12246890
Actually, http://www.lmc-mediaagentur.de/dpool/tips/0995.htm should help you fill the menu for test purposes.
0
 

Author Comment

by:Joeri_
ID: 12247020
That second url you gave me is for a normal mainmenu.
But i found also on that site one for ActionMainMenuBar, but (yes here it comes again), it still doesnt work.

procedure Thoofdscherm.Button1Click(Sender: TObject);
var
  Item: TActionClientItem;
begin
  Item := ActionManager1.FindItemByCaption('E&xit');
  if Assigned(Item) then
    ActionManager1.AddCategory('File', Item);
end;

Item remains nil, i cant get it to get a value.
But there is an action i added to the ActionManager, it the standard action Exit, and it does have this caption.
Any ideas ?
0
 
LVL 3

Expert Comment

by:Sabre
ID: 12247227
sorry, got busy there - try ActionManagerHelper1.FindItemByCaption
0
 
LVL 3

Expert Comment

by:Sabre
ID: 12247249
var
fItem: TActionClientItem;
begin
    // Look for caption  'E&xit'
    fItem := ActionManagerHelper1.FindItemByCaption('E&xit');
    if Assigned(fItem) then
      begin
              // Found Item?
              showmessage('Item Found');
              // Work with Item
              fItem.Control.Enabled := not fItem.Control.Enabled;
      end;
end;

The above is off the top of my head

0
 
LVL 3

Expert Comment

by:Sabre
ID: 12247292
oops - I forgot that ActionManagerHelper is a component (serves me right for quickly reading some code snippets i have here on the machine without looking at Delphi)

The component is available from:

http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=17128
0
 

Author Comment

by:Joeri_
ID: 12247371
I installed the component, and used it in my form. But i still have to same problem.

procedure Thoofdscherm.Button1Click(Sender: TObject);
var
fItem: TActionClientItem;
begin
// Look for caption  'E&xit'
fItem := ActionManagerHelper1.FindItemByCaption('E&xit');
  if Assigned(fItem) then
    begin
      // Found Item?
      showmessage('Item Found');
      // Work with Item
      fItem.Control.Enabled := not fItem.Control.Enabled;
    end;

end;

fItem = nil

It's really unbelievable, you still have another idea ?
Thanks for all the help
0
 
LVL 2

Expert Comment

by:cula99
ID: 12247418
Try to rename forms and menus as in Delphi and to insert some coment, maby it will be more understandable. Like Form1, Form2, ... ActionMainMenuBar1, ActionMainMenuBar2, ActionMainMenuBar3,... ActionManager1, ActionManager2,...

procedure MainForm.Button1Click(Sender: TObject);
begin
  MainForm:=       ToverzichtenMenu.Create(hoofdmenu.hoofdscherm);    ??????????????????
  try
    MainForm.ShowModal;
  finally
    MainForm.Release;
  end;
end;
0
 
LVL 3

Expert Comment

by:Sabre
ID: 12247490
If fItem is returning nil then it must not exist - did you free the items anywhere?

 
0
 

Author Comment

by:Joeri_
ID: 12247496
Ok, i found out this:
If there is already an item in the ActionMainMenuBar, and that one is called in example '&test' you can add new categories.

procedure TMainForm.Button1Click(Sender: TObject);
begin
  ActionManagerHelper1.AddCategory('Edit', ActionManagerHelper1.FindItemByCaption('&test'));
end;

That works, but now it has to work with a completely empty ActionMainMenuBar.

Here is some renamed code:
Code for creating & showing form2.

procedure TMainForm.Button1Click(Sender: TObject);
begin
  Form2 := TForm2.Create(MainForm);
  try
    Form2.ShowModal;
  finally
    Form2.Release;
  end;
end;

0
 

Author Comment

by:Joeri_
ID: 12247502
No, i don't free the items anywhere.
0
 
LVL 3

Accepted Solution

by:
Sabre earned 50 total points
ID: 12247571
> but now it has to work with a completely empty ActionMainMenuBar

If the ActionMainMenuBar is empty then  if Assigned(fItem)  would always return nil since there is nothing there - use  if not Assigned(fItem)  and see if that fixes it
0
 

Author Comment

by:Joeri_
ID: 12247675
Ok, i completely changed the code, but now it adds something to an empty bar, so thats something. Now i think i can find out the rest.
Thanks for all the help, ill give you the points Sabre.

Here is the solution i found:

procedure Thoofdscherm.FormCreate(Sender: TObject);
var
  NewAction: TAction;
begin
  NewAction := TAction.Create(Self);
  NewAction.Caption := 'Test';
  NewAction.Category := 'TestCat';
  NewAction.Name := 'Test';

  ActionManager1.AddAction(NewAction, nil);
  with ActionMainMenuBar1.ActionClient.Items.Add do
    Action := NewAction;
end;
0
 
LVL 3

Expert Comment

by:Sabre
ID: 12247707
try this and see if it works

var
  NewAction: TAction;
begin
  NewAction := TAction.Create(Self);
  NewAction.Caption := 'Test';
  NewAction.Category := 'File';
  NewAction.Name := 'TestFile';
  NewAction.OnExecute := Test;

  ActionManager.AddAction(NewAction, nil);

  with ActionToolBar1.ActionClient.Items.Add do
    Action := NewAction;
end;

procedure TForm1.Test(Sender: TObject);
begin
  ShowMessage('Test');
end;


0
 
LVL 3

Expert Comment

by:Sabre
ID: 12247712
oops, didn't see your last post.
0
 

Author Comment

by:Joeri_
ID: 12247772
Hehe :) Thanks anyway.

This works well, now i only have to find out how to add subitems here .. but I think with some time ill find that one out :)
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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to debug For loops? 3 56
Convert MS Word document to a PDF file 9 90
Firemonkey webbrowser scrollbars ? 1 50
DBCtrlGrid, Delphi, Scroll 7 26
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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