>> Please do post the code on the list.
It's not overly pretty but it works for me...
I use an ini file to adjust the caption of the top level menu item. you
can just remove that.
because this is one of many of my experts you will note that I first check
to see if the top level menu
exists. You can remove this reference.
// inserts the menu item.
procedure TNewApplicationExpert.InstallAddIn;
var
MainMenu: TIMainMenuIntf;
ReferenceMenuItem: TIMenuItemIntf;
ParentMenu: TIMenuItemIntf;
Flags: TIMenuFlags;
begin
try
Flags := [mfEnabled, mfVisible];
MainMenu := ToolServices.GetMainMenu;
if MainMenu <> nil then
begin
try
// install the main menu
ReferenceMenuItem := MainMenu.FindMenuItem('JED_MyExpertList');
if ReferenceMenuItem = nil then
begin
InstallJEDExpertMenu;
// install the menu items under the main menu
ReferenceMenuItem := MainMenu.FindMenuItem('JED_MyExpertList');
end;
if ReferenceMenuItem <> nil then
begin
try
NewAppItem := ReferenceMenuItem.InsertItem(0, '&New Application
Expert',
'JEDExpertNewAppExpertItem',
'Create a New
Application',
0, 0, 0, Flags,
OnClick);
finally
ReferenceMenuItem.Free;
end;
end;
finally
MainMenu.Free;
end;
end;
except
handleexception;
end;
end;
procedure TNewApplicationExpert.InstallJEDExpertMenu;
var
lMenuItem: TMenuItem;
lIndex: Integer;
lMainIDEFrm: TCustomForm;
begin
lMainIDEFrm := Application.FindComponent('AppBuilder') as TCustomForm;
if lMainIDEFrm <> nil then
begin
// get the main menu component in delphi IDE.
lMenuItem := TMenuItem(lMainIDEFrm.FindComponent('HelpMenu'));
// see if there is a specific index spot for the menu
lIndex := GetIniIntValue('Main Menu', 'Index', -1);
// if no index spot and we have a reference to the Menu Item then
// insert the new item before the Help Menu item (which is what we
got).
if (lMenuItem <> nil) and (lIndex = -1) then
lIndex := lMenuItem.MenuIndex;
InsertJEDExpertMenu(lIndex);
end;
end;
procedure TNewApplicationExpert.InsertJEDExpertMenu(aInsertIndex: Integer);
var
lMainMenu: TIMainMenuIntf;
lMenuItem: TIMenuItemIntf;
lMenuCaption: String;
lMenuDesc: String;
lReturn: array of String;
begin
SetLength(lReturn, 2);
if not GetIniStringValues('Main Menu', ['Caption', 'Desc'], lReturn) then
begin
lMenuCaption := lReturn[0];
lMenuDesc := lReturn[1];
end
else
begin
lMenuCaption := '&JED Experts';
lMenuDesc := 'JED''s Experts list';
end;
lMainMenu := ToolServices.GetMainMenu;
try
lMenuItem := lMainMenu.GetMenuItems;
try
FJEDExpertMenuItem := lMenuItem.InsertItem(aInsertIndex,
lMenuCaption, 'JED_MyExpertList',
lMenuDesc, 0, 0, 0, [mfVisible, mfEnabled],
nil);
finally
lMenuItem.Free;
end;
finally
lMainMenu.Free;
end;
end;
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"