[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Adding a menu item to the main menu items

Posted on 1998-12-29
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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? http://www.gexperts.com/opentoolsframe.html

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.

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

650 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