I am reading part of menu from database and I need to add items when app is
starting.
Chris
--
Krzysztof Swiatkowski, Warszawa, PL, | mailto:hop...@bigfoot.com
_______________________________________| http://hobbit.republika.pl
Computers run on smoke. If it leaks out, they won't work.
Did you get any help? I have the same problem. Before I have used
TMainMenu for that but with D6 would be nice to use TActionMainMenuBar.
Regards
Rado Antloga
"Krzysztof Swiatkowski" <hop...@bigfoot.com> wrote in message
news:6d9votclsngi0ntmq...@news.hopbit.pl...
>Hi,
>
>Did you get any help? I have the same problem. Before I have used
>TMainMenu for that but with D6 would be nice to use TActionMainMenuBar.
No luck so far. I did manage to add items in some weidr way but their action
are is not getting executed correctly - AV's on first click no reaction on
subsequent clicks. And it didn't even get to my function.
Chris
--
Krzysztof Swiatkowski, Warszawa, PL, | mailto:hop...@bigfoot.com
_______________________________________| http://hobbit.republika.pl
Bardzo milo jest waznym, ale wazniejsze jest byc milym.
{-------------------------------------}
procedure TForm3.BitBtn3Click(Sender: TObject);
var
ClientItem: TActionClientItem;
i: integer;
begin
for i := 0 to ActionManager1.ActionCount - 1 do
begin
if ActionManager1.Actions [i].Category = 'b1' then
begin
ClientItem :=
ActionMainMenuBar1.ActionControls[0].ActionClient.items.add;
ClientItem.caption:='b1';
ClientItem.action:=nil;
ClientItem:= ClientItem.Items.add;
ClientItem.action:= ActionManager1.Actions [i];
end;
end;
end;
{---------------------------------------------}
you will need this typed record (optional)
TMenuItemRec = packed record
ID: integer;
ParentID: integer;
Caption : wideString;
Bitmap : wideString;
ShortCut : wideString;
GroupIndex : Integer;
HelpContext : Longint;
Checked : wordBool;
Enabled : wordBool;
RadioItem : wordBool;
Visible : wordBool;
end;
//--------------------------------------
//this is where you start
function TfrmMain.MenuAddMenuItem(const MenuProperties: TMenuItemRec):
HResult;
var
TargetClientItem: TActionClientItem;
begin
try
if MenuProperties.ParentID= ctTopMenu then
begin
AddTopMenu(MenuProperties);
end
else if iCurrentTopMenuID= MenuProperties.ParentID then
begin
AddMenuItem(MenuProperties,
FActionMainMenuBar.ActionControls[iCurrentTopMenu].ActionClient);
end
else
begin
if iCurrentTopMenu= -1 then
begin
Result:= S_FALSE;
raise EGeneralException.create('Failed to add in a Menu Item
because a top menu have not been assigned: MenuAddMenuItem');
exit;
end
else
begin
TargetClientItem:= nil;
if FindMenuItem(MenuProperties.ParentID,
FActionMainMenuBar.ActionControls[iCurrentTopMenu].ActionClient,
TargetClientItem) = S_OK then
AddMenuItem(MenuProperties, TargetClientItem);
end;
end;
Result:= S_OK;
except
Result:= S_FALSE;
raise EGeneralException.create('Failed to add in a Menu Item in
MenuAddMenuItem');
end;
end; {MenuAddMenuItem}
//-------------------------------
//add the very top menu item
function TfrmMain.AddTopMenu(
const MenuProperties: TMenuItemRec): HResult;
var
DragObject: TDragObject;
aciTopMenu: TActionClientItem;
acMenuBar: TActionClients;
iCount: integer;
begin
try
acMenuBar:= FActionMainMenuBar.ActionClient.ActionBar.ActionClient.Items;
if acMenuBar.Count= 0 then
aciTopMenu:= acMenuBar.Add
else
begin
for iCount:= 0 to acMenuBar.Count- 1 do
begin
if acMenuBar[iCount].MergeIndex> MenuProperties.GroupIndex
then
break;
end;
aciTopMenu:= TActionClientItem(acMenuBar.insert(iCount));
end;
aciTopMenu.Caption:= MenuProperties.caption;
aciTopMenu.MergeIndex:= MenuProperties.GroupIndex;
acMenuBar[aciTopMenu.Index].Caption:= MenuProperties.caption;
aciTopMenu.Control.CalcBounds;
aciTopMenu.Visible:= True;
aciTopMenu.Control.Enabled:= True;
iCurrentTopMenu:= aciTopMenu.Index;
iCurrentTopMenuID:= MenuProperties.ID;
lstTopMenuCaptions.add(MenuProperties.caption);
Result:= S_OK;
except
Result:= S_FALSE;
raise EGeneralException.create('Failed to add a top menu in
AddTopMenu');
end;
end; {AddTopMenu}
//--------------------------------------------------------
function TfrmMain.AddToActionManager(
const MenuProperties: TMenuItemRec): TAction;
var
TempAction: TAction;
begin
try
TempAction:= TAction.create(FActionManager);
TempAction.ActionList:= FActionManager;
TempAction.Caption:= MenuProperties.Caption;
TempAction.Tag:= MenuProperties.ID;
TempAction.ImageIndex:= 0;
TempAction.ShortCut:= TextToShortCut(MenuProperties.ShortCut);
TempAction.GroupIndex:= MenuProperties.GroupIndex;
TempAction.HelpContext:= MenuProperties.HelpContext;
TempAction.Checked:= MenuProperties.Checked;
TempAction.Enabled:= MenuProperties.Enabled;
TempAction.Visible:= MenuProperties.Visible;
TempAction.OnExecute:= MenuItemOnClick;
result:= TempAction;
except
raise EGeneralException.create('Failed to create an action in
AddToActionManager');
result:= nil;
end;
end;{AddToActionManager}
//----------------------------------------------------
function TfrmMain.AddMenuItem(MenuProperties: TMenuItemRec;
aciParent: TActionClientItem): integer;
var
ActionToAdd: TAction;
ClientItem: TActionClientItem;
stCategory: string;
begin
try
ActionToAdd:= AddToActionManager(MenuProperties);
stCategory:= aciParent.DisplayName;
Delete(stCategory, pos('&', stCategory), 1);
ActionToAdd.Category:= stCategory;
if lstActionCategory.IndexOf(stCategory)= -1 then
lstActionCategory.Add(stCategory);
ClientItem:= aciParent.items.add;
ClientItem.Action:= ActionToAdd;
Result:= S_OK;
except
Result:= S_FALSE;
raise EPluginGeneralException.create('Failed to add a menu item to
a Top Menu in AddTopMenu');
end;
end;
//-------------------------------------------------
function TfrmMain.FindMenuItem(iMenuItemID: integer;
aciStartFrom: TActionClientItem;
var aciTarget: TActionClientItem): HRESULT;
var
iCount: integer;
begin
try
Result:= S_FALSE;
for iCount:= 0 to aciStartFrom.Items.Count- 1 do
begin
if aciStartFrom.Items[icount].Items.Count> 0 then
if FindMenuItem(iMenuItemID, aciStartFrom.Items[icount],
aciTarget)= S_OK then
begin
Result:= S_OK;
break;
end;
if assigned(aciStartFrom.Items[icount].Action) then
begin
if iMenuItemID= aciStartFrom.Items[icount].Action.Tag then
begin
Result:= S_OK;
aciTarget:= aciStartFrom.Items[icount];
break;
end;
end;
end;
except
Result:= S_FALSE;
raise EPluginGeneralException.create('Failed to find a Menu Item
in FindMenuItem');
end;
end;