Adding a menu item to the main menu items

Posted on 1998-12-29
Last Modified: 2010-04-04
Hello All,

I would like my wizards (which currently reside in the Tools menu) to appear in their own menu item (just preceding the Help menu item). I am surprised; that what I thought was straightforward has proven to be rather elusive. Please don't launch into a long discourse about TIMenuItemIntf, I just want the line(s) of code to create a stand-alone separate menu item.

Question by:Edo082297
  • 3
  • 2
  • 2

Expert Comment

ID: 1353637
I'm guessing you talk of Delphi mainmenu or do you talk of your own programs mainmenu?

Expert Comment

ID: 1353638
Hi Edo,

I start with my first guess, the Delphi mainmenu :

ever read these pages?

another, more appropriate, because you ask for code is this :

especially from 8. TAddInMenuListExpert

Hope, that you now have the code you need and some more code you never asked for, but my guess is that you don't mind this

Regards, Zif.

Author Comment

ID: 1353639
Hello ZifNab

Your paltry attempt at an aswer should have been posted as a comment. I digested both Dr.Bob's article on Delphi Wizards and the OpenTools API, the GExpert article and the source code to GExpert's long ago. (I cannot obtain Gerald Nunn's method of adding a main menu item since he uses a function call that is part of Ray Lischener's _Hidden Paths_ companion source (or is it _Secrets ...?) source, and is thus not reproducible).

You are getting lazy in your lofty position, try again.

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.


Expert Comment

ID: 1353640
Hi Edo

I'm posting this as a comment so I don't get blasted like ZifNab!!  ;-)

In my expert's constructor, I declare 2 variables:
  MainMenu: TIMainMenuIntf;
  MenuItems: TIMenuItemIntf;

Also, NewMainMenuItem and NewMenuItem are declared in the expert as TIMenuItemIntf.  They are freed in the expert's destructor.

I insert the menu as follows:
  MainMenu := ToolServices.GetMainMenu;
  if (MainMenu <> nil) then
      MenuItems := MainMenu.GetMenuItems;
      if (MenuItems <> nil) then
          // Add item to Delphi's main menu bar.
          NewMainMenuItem := MenuItems.InsertItem(8, '&Test', 'TestMainMenuItem', '', 0, 0, 0, [mfVisible, mfEnabled], nil);

          // Add a sub menu to the new menu item.
          NewMenuItem := NewMainMenuItem.InsertItem(0, '&Sub Item', 'NewSubMenuItem', '', 0, 0, 0, [mfVisible, mfEnabled], OnSubClick);

Hope this helps you.

Author Comment

ID: 1353641
Hello JB

Thankyou for your correct posting. I am now wondering what I wrote at work, it seems eerily similar, however I think I was trying an insert without the GetMenuItems call. Hmmm....

I wouldn't have blasted Zifnab had the section he refers to in Dr.Bob's article actually added a main menu item. It does not (unless there is a new version of the article, in which case I apologize profusely, and feel rather silly). The article adds a sub menu item to the Tools menu.

Post an answer...

Baie danke


Expert Comment

ID: 1353642

From the bloody mess and still smoking body parts, you see on the floor right before you (it used to be ZifNab) I can only say :

1. I can't smell you already read these articles
2. You've to admit that this is rich information for the unknown
3. You knew how to enter SubMenu's? Correct?
4. Looking at the simple proposed code you can see the GetMainMenu method?
5. Knowing 3 and seeing 4, little step to put your wizards in your own 'mainmenu'.
6. And wouldn't it be great to get more code than you wanted? With full explenation? (but offcourse I didn't knew 1)
7. If you already had some code, you could also have posted it here. That's easier to see the problem.

But heck, who am I. Just somebody who wants to help people on a freely non-profit basis. Who is offcourse not always right (I always say that there are far more better 'experts' on this site than I am, I'm even not a programmer from education or job) and is most of the time talking out of his head.

Now, I'll take my escape through the sewer so my blood will be mixed by wather and I'll be invisible. And then I'm gone...

** poof **

Only few words in the sky will remember you that I was here :

Both, have a nice 1999.

Zif (R.I.P. 29 december 1998)

Accepted Solution

JimBob091197 earned 50 total points
ID: 1353643
Hi all

Edo: I am posting an answer now!

Zif: Nice speech, man!  :)


P.S.  There was once a big debate on this site about whether code is better or a reference to another web site.  I still prefer a few short lines of code rather than wading through a lot of stuff on another web site, but as Zif says in #6 - you usually get more code than you wanted...

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now