Delphi open tools api-how to create and add new menu item

Source: Internet
Author: User

I have introduced how to compile a menu wizard ), however, the menu item can only be used as a sub-item of the "help" menu in the Delphi IDE environment. What should we do if we want to insert our own menu items in any position in the main menu of Delphi ide?

In fact, the method is very simple. You only need to write an add-in Wizard plug-in expert to insert the menu into the main menu of Delphi IDE in its constructor, the newly inserted menu items are parsed In the destructor.

First, we need to define some private members in the expert class to save the main menu of Delphi IDE and the newly created menu items.

Fmainmenu: tmainmenu;
Fnewmenuitem: tmenuitem;

The next step is to obtain an example of the Delphi ide Main Menu object in the constructor, create a new menu item, and insert it.

// Find Delphi's main menu
Fmainmenu: = (borlandideservices as intaservices). mainmenu;

// Create new menu item
Fnewitem: = tmenuitem. Create (NiL );
Fnewitem. Caption: = 'add-in menu ';
Fnewitem. onclick: = menuitemclick;

// Insert new menu item
Fmainmenu. Items. insert (fmainmenu. Items. Count-1, fnewitem );

Finally, we need to release the menu items we have inserted in the destructor.

 

Fmainmenu. Items. Remove (fnewitem );
Fnewitem. Free;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.