【问题标题】:Delphi IDE custom menu items, how to Add them?Delphi IDE自定义菜单项,如何添加?
【发布时间】:2012-04-23 07:51:34
【问题描述】:

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

对于delphi 7 像这样

我在网上搜索了有关添加菜单项的信息,但我没有任何东西可以像 EurekaLog 那样向 IDE 添加项目。 任何人都可以告诉我如何添加像 EurekaLogmysql 这样的项目吗? 它在注册表中的某个位置吗?

【问题讨论】:

标签: delphi delphi-7 menuitem delphi-2006


【解决方案1】:

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

LMainMenu:=(BorlandIDEServices as INTAServices).MainMenu;

LMainMenu:=(BorlandIDEServices as INTAServices).GetMainMenu;

然后添加您想要的菜单项。

查看这些链接以获取更多示例

【讨论】:

  • 如何给菜单项添加图标?
  • 阅读 RRUZ 给你的链接。最后一个链接有一个部分告诉你该怎么做。搜索图标。
【解决方案2】:

如果您想专门向 HELP 菜单添加一个菜单项,并在您的包卸载时将其删除,并处理项目的启用/禁用,那么此向导代码可能会有所帮助。我将 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.

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

【讨论】:

  • 你好,究竟是为了调试这个HelloWizard.Execute;?我已经尝试在那里访问注册表..它会违反访问权限
  • 我相信还有其他问题可以详细说明。看看这个:stackoverflow.com/questions/8313697/…
猜你喜欢
  • 1970-01-01
  • 2015-02-17
  • 2012-10-24
  • 2021-01-18
  • 2014-04-22
  • 2016-11-18
  • 2012-09-16
  • 2017-04-23
  • 1970-01-01
相关资源
最近更新 更多