Delphi IDE自定义菜单项,如何添加它们?

时间:2012-04-23 07:51:35

标签: delphi delphi-7 menuitem delphi-2006

我正在使用Delphi 7Delphi 2006开发一个项目,我正在开发一个可以获取某些系统信息的组件。 现在的要求是在系统上安装组件之后,IDE上应该有一个菜单项,如下所示

enter image description here

delphi 7这样的 enter image description here

我在网上搜索了有关添加菜单项的内容,但我没有任何内容可以像IDE那样添加一个项目到EurekaLog。 任何机构都可以告诉我如何添加EurekaLogmysql这样的项目吗? 它是在注册表中的某个地方吗?

2 个答案:

答案 0 :(得分:14)

要将菜单添加到Delphi IDE,您必须使用Delphi Open Tools API。从这里你可以使用这样的代码访问delphi IDE的主菜单。

LMainMenu:=(BorlandIDEServices as INTAServices).MainMenu;

LMainMenu:=(BorlandIDEServices as INTAServices).GetMainMenu;

然后添加所需的菜单项。

检查这些链接以获取其他样本

答案 1 :(得分:4)

如果要将菜单项专门添加到“帮助”菜单中,并在卸载程序包时将其删除,并处理项目的启用/禁用,则此向导代码可能会有所帮助。我将GExperts文档显示的示例向导代码作为初始项目,并将其作为一个稍微好一点的启动项目发布在此处。如果您获取此代码并将其扩展,您可以非常快速地开始使用:

https://bitbucket.org/wpostma/helloworldwizard/

“向导”的意思是“简单的IDE专家”,即添加到IDE的菜单,它实现了IOTAWizard和IOTAMenuWizard。这种方法有很多好处,也是编写GExperts向导的方式。

代码的核心是这个启动向导,需要将其放入包(DPK)并安装,并在IDE中注册:

// "Hello World!" for the OpenTools API (IDE versions 4 or greater)
// By Erik Berry: http://www.gexperts.org/, eberry@gexperts.org

unit HelloWizardUnit;

interface

uses ToolsAPI;

type
  // TNotifierObject has stub implementations for the necessary but
  // unused IOTANotifer methods
  THelloWizard = class(TNotifierObject, IOTAMenuWizard, IOTAWizard)
  public
        // IOTAWizard interface methods(required for all wizards/experts)
        function GetIDString: string;
        function GetName: string;
        function GetState: TWizardState;
        procedure Execute;
        // IOTAMenuWizard (creates a simple menu item on the help menu)
        function GetMenuText: string;
  end;


implementation

uses Dialogs;

procedure THelloWizard.Execute;
begin
  ShowMessage('Hello World!');
end;

function THelloWizard.GetIDString: string;
begin
  Result := 'EB.HelloWizard';
end;

function THelloWizard.GetMenuText: string;
begin
  Result := '&Hello Wizard';
end;

function THelloWizard.GetName: string;
begin
  Result := 'Hello Wizard';
end;

function THelloWizard.GetState: TWizardState;
begin
  Result := [wsEnabled];
end;

end.

注册码未在上面显示,但如果您从上面的链接下载,则会将其包含在自己的“注册”(注册)单元中。 A tutorial link is on EDN here.