我使用 INTAServices40 在 Delphi 中成功安装了我的菜单项,但问题是 - 下次 Delphi 启动时菜单丢失?!实际上,安装了两个菜单项;帮助菜单下的一个总是显示(IOTAWizardMenu),但工具菜单下的一个(测试菜单项)在下次 Delphi 启动时丢失。如何解决这个问题?
unit TESTMENU;
interface
uses
ToolsAPI, Classes, Windows, vcl.Menus, vcl.dialogs;
type
TCustomMenuItem = class(TNotifierObject, IOTAWizard, IOTAMenuWizard)
function GetIDString: string;
function GetName: string;
function GetState: TWizardState;
// Launch the AddIn
procedure Execute;
function GetMenuText: string;
end;
TCustomMenuHandler = class(TObject)
// Handle custom menu
procedure HandleClick(Sender: TObject);
end;
procedure Register;
implementation
var
mnuitem: TMenuItem;
CustomMenuHandler: TCustomMenuHandler;
procedure TCustomMenuItem.Execute;
begin
ShowMessage('IOTAWizardMenu based menu item');
end;
function TCustomMenuItem.GetIDString: string;
begin
Result := 'TMS.MenuSample';
end;
function TCustomMenuItem.GetMenuText: string;
begin
Result := 'IOTAWizardMenu';
end;
function TCustomMenuItem.GetName: string;
begin
Result := 'TMSMenuSample';
end;
function TCustomMenuItem.GetState: TWizardState;
begin
Result := [wsEnabled];
end;
procedure TCustomMenuHandler.HandleClick(Sender: TObject);
begin
ShowMessage('INTAServices40.MainMenu based menu item');
end;
procedure AddIDEMenu;
var
NTAServices: INTAServices40;
begin
NTAServices := BorlandIDEServices as INTAServices40;
// avoid inserting twice
if NTAServices.MainMenu.Items[9].Find('TEST') = nil then
begin
CustomMenuHandler := TCustomMenuHandler.Create;
mnuitem := TMenuItem.Create(nil);
mnuitem.Caption := 'TEST';
mnuitem.OnClick := CustomMenuHandler.HandleClick;
NTAServices.MainMenu.Items[9].Add(mnuitem)
end;
end;
procedure RemoveIDEMenu;
var
NTAServices: INTAServices40;
begin
if Assigned(mnuitem) then
begin
NTAServices := BorlandIDEServices as INTAServices40;
NTAServices.MainMenu.Items[9].Remove(mnuitem);
mnuitem.Free;
if Assigned(CustomMenuHandler) then
CustomMenuHandler.Free;
end;
end;
procedure Register;
begin
AddIDEMenu;
RegisterPackageWizard(TCustomMenuItem.Create);
end;
initialization
mnuitem := nil;
CustomMenuHandler := nil;
finalization
RemoveIDEMenu;
end.
所以,我的第一个问题是如何在每次 Delphi 启动时显示菜单项 TEST。另外,我想在菜单项 TEST 旁边添加图标。有什么方向吗?
谢谢
编辑: 我刚刚发现我的包裹延迟加载。看网上的人说 ForceDemandLoadState(dlDisable) 应该被调用。但是,这对我也没有帮助......