Joeri_
asked on
Menuitems dissapear
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.overzichtBtnC lick(Sende r: TObject);
begin
overzichtenMenu := ToverzichtenMenu.Create(ho ofdmenu.ho ofdscherm) ;
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.
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.overzichtBtnC
begin
overzichtenMenu := ToverzichtenMenu.Create(ho
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.
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).
ASKER
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 ?
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 ?
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.
Actually, http://www.lmc-mediaagentur.de/dpool/tips/0995.htm should help you fill the menu for test purposes.
ASKER
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.FindItemByC aption('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 ?
But i found also on that site one for ActionMainMenuBar, but (yes here it comes again), it still doesnt work.
procedure Thoofdscherm.Button1Click(
var
Item: TActionClientItem;
begin
Item := ActionManager1.FindItemByC
if Assigned(Item) then
ActionManager1.AddCategory
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 ?
sorry, got busy there - try ActionManagerHelper1.FindI temByCapti on
var
fItem: TActionClientItem;
begin
// Look for caption 'E&xit'
fItem := ActionManagerHelper1.FindI temByCapti on('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
fItem: TActionClientItem;
begin
// Look for caption 'E&xit'
fItem := ActionManagerHelper1.FindI
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
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
The component is available from:
http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=17128
ASKER
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.FindI temByCapti on('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
procedure Thoofdscherm.Button1Click(
var
fItem: TActionClientItem;
begin
// Look for caption 'E&xit'
fItem := ActionManagerHelper1.FindI
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
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(Send er: TObject);
begin
MainForm:= ToverzichtenMenu.Create(ho ofdmenu.ho ofdscherm) ; ??????????????????
try
MainForm.ShowModal;
finally
MainForm.Release;
end;
end;
procedure MainForm.Button1Click(Send
begin
MainForm:= ToverzichtenMenu.Create(ho
try
MainForm.ShowModal;
finally
MainForm.Release;
end;
end;
If fItem is returning nil then it must not exist - did you free the items anywhere?
ASKER
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(Sen der: TObject);
begin
ActionManagerHelper1.AddCa tegory('Ed it', ActionManagerHelper1.FindI temByCapti on('&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(Sen der: TObject);
begin
Form2 := TForm2.Create(MainForm);
try
Form2.ShowModal;
finally
Form2.Release;
end;
end;
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(Sen
begin
ActionManagerHelper1.AddCa
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(Sen
begin
Form2 := TForm2.Create(MainForm);
try
Form2.ShowModal;
finally
Form2.Release;
end;
end;
ASKER
No, i don't free the items anywhere.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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(Se nder: TObject);
var
NewAction: TAction;
begin
NewAction := TAction.Create(Self);
NewAction.Caption := 'Test';
NewAction.Category := 'TestCat';
NewAction.Name := 'Test';
ActionManager1.AddAction(N ewAction, nil);
with ActionMainMenuBar1.ActionC lient.Item s.Add do
Action := NewAction;
end;
Thanks for all the help, ill give you the points Sabre.
Here is the solution i found:
procedure Thoofdscherm.FormCreate(Se
var
NewAction: TAction;
begin
NewAction := TAction.Create(Self);
NewAction.Caption := 'Test';
NewAction.Category := 'TestCat';
NewAction.Name := 'Test';
ActionManager1.AddAction(N
with ActionMainMenuBar1.ActionC
Action := NewAction;
end;
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(Ne wAction, nil);
with ActionToolBar1.ActionClien t.Items.Ad d do
Action := NewAction;
end;
procedure TForm1.Test(Sender: TObject);
begin
ShowMessage('Test');
end;
var
NewAction: TAction;
begin
NewAction := TAction.Create(Self);
NewAction.Caption := 'Test';
NewAction.Category := 'File';
NewAction.Name := 'TestFile';
NewAction.OnExecute := Test;
ActionManager.AddAction(Ne
with ActionToolBar1.ActionClien
Action := NewAction;
end;
procedure TForm1.Test(Sender: TObject);
begin
ShowMessage('Test');
end;
oops, didn't see your last post.
ASKER
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 :)
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 :)