Delphi IDE custom menu items, how to Add them?
Asked Answered
J

2

6

I am working on a project using Delphi 7 and Delphi 2006, i am developing a component that will get certain system information. Now the requirement is that after the component is installed on the system, there should be a menu item on the IDE , like this

enter image description here

and for delphi 7 like this enter image description here

i have searched on the net about adding a menu item but i have not got anything to add an item to the IDE like the one EurekaLog has. can any body tell me how to add the item like EurekaLog or mysql ? is it some where in the registry?

Jeffrey answered 23/4, 2012 at 7:51 Comment(2)
lookup GExperts source code(gexperts.svn.sourceforge.net/viewvc/gexperts), this way you can learn how to extend the IDE as you pleaseMaxim
Or CnWizards has also source code available, but it's quite big project to learn from.Dominations
R
15

To add a menu to the Delphi IDE you must use the Delphi Open Tools API. from here you can access the Main menu of the delphi IDE using a code like this.

LMainMenu:=(BorlandIDEServices as INTAServices).MainMenu;

or

LMainMenu:=(BorlandIDEServices as INTAServices).GetMainMenu;

And then add the menu items which you want.

Check these links for additional samples

Remit answered 23/4, 2012 at 8:4 Comment(2)
How to Add icons to the menu items?Jeffrey
Read the links that RRUZ gave you. The final link has a section which tells you what to do. Search for icon.Imperial
A
4

If you want to specifically add a menu item to the HELP menu, and also make it get removed when your package unloads, and handle enable/disable of the items, then this wizard code might be helpful. I took the sample wizard code that GExperts documentation shows as a starter project, and posted it up here as a slightly nicer start project. You can get started very quickly if you grab this code and just extend it:

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

What they mean by "Wizard" is a "simple IDE Expert", that is, something with a menu added to the IDE, that implements IOTAWizard and IOTAMenuWizard. This approach has many benefits and is the way that the GExperts wizards are written.

The core of the code is this starter wizard, which needs to be put into a package (DPK) and installed, and registered with the IDE:

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

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.

The registration code is not shown above, but is included in its own "Reg" (registration) unit if you download this from the link above. A tutorial link is on EDN here.

Addis answered 24/4, 2012 at 23:0 Comment(2)
hello, hw exactly to debugg this HelloWizard.Execute; ? i have tried acessing registry there..it give acess violationJeffrey
I believe there are other questions that detail it. Check this one out: #8314197Addis

© 2022 - 2024 — McMap. All rights reserved.