Author Topic: MainMenu: How to use the "Quit <App>" item that has been added in trunk?  (Read 1473 times)


  • Hero Member
  • *****
  • Posts: 679
    • Tweaking4All
I have noticed that, in trunk, when adding a TMainMenu to the main form, an application menu with a "Quit Application" menu item will be added.

Does anyone know where the use of this is documented or how it can be disabled?
In most of my application the "Quit" menu item and at times it does seem to work or conflict with my existing menu's (I use the Wiki documented method).

- How can I assign a procedure to the "Quit application menu" item (not listed in the menu editor)? In most applications it doesn't do anything (or conflicts).
- How do I add other menu items to this menu? After all it is not uncommon under macOS to add for example "Settings" or "Preferences" there as well.
- Worse case: how to disable this feature?

Or is this something I should report in Bug Tracker?
Note: I can see and appreciate the great intend and why it may be a good idea to add something like this, but maybe something needs to be documented or even be implemented slightly different? Or I'm just missing some info.


  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #1 on: January 07, 2024, 01:23:19 am »
I also use trunk but maybe a different version.
On my version I can not confirm your sayings.
This is how I do:
1. drop a TMainMenu on your Form.
2. doubleclick it to open the menu designer (image 1)
3. Design it
4. create events in object inspector by doubleclick the menu item (image 2)
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »


  • Hero Member
  • *****
  • Posts: 679
    • Tweaking4All
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #2 on: January 07, 2024, 04:45:12 pm »

KodeZwerg: you're right - the steps you're doing work the same for me as well.
But this wasn't the issue I meant to ask about.  :)

Maybe I didn't explain myself properly. What I meant, is editing the predefined application menu, by adding items, or changing procedures.

Test 1:
When you make a new application, and you do not add a MainMenu, then when running the application and empty "project1" application menu will appear.

Test 2:
Same test, but now we add a MainMenu to the form, without adding any menu items!
Now when you run the application you will see that the application menu has a few predefined items (see my screenshot).
Some are predefined by macOS (Services, and the hide/show items) and one that has been added by Lazarus (Quit project1).

The issue I run into is that at designtime this automatically added menu is not shown in the menu editor, and I do not seem to have any easy options to add more items to the already existing "project1" menu, or change the "Quit" behavior.

So yes, I can add new menu's, each with whatever items I want. Those added menu's works as expected.

But I cannot add an item to the "project1" application menu (the one shown in the screenshot), or influence what clicking the "Quit project1" does.

In my applications I use the method described in the Wiki to add this application menu and I was able to freely add other items (as seen with other macOS applications).

For example:
I would add a menu item "Settings..." about the "Services" menu item ©mpare the screenshot from Lazarus and my previous screenshot).
So what is the recommended method to do this?

Also: how can I assign a procedure to the "Quit project1" menu item?


  • Hero Member
  • *****
  • Posts: 12067
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #3 on: January 07, 2024, 06:24:23 pm »
I am not a mac-specialist, but I am afraid that you cannot modify this menu (at least not within the framework of the LCL) since it seems to be created by the OS.


  • Hero Member
  • *****
  • Posts: 679
    • Tweaking4All
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #4 on: January 07, 2024, 06:45:13 pm »
Thanks for chiming in wp. It's much appreciated.

However, you can modify parts of this menu, as described in the Wiki (link).
I was just wondering if there could be a better way to do this.

Thanks all for chiming in. Maybe I can come up with something myself 😊 (I'll share if I do)


  • New member
  • *
  • Posts: 9
hi, Hansaplast

in Lazarus Main Trunk,Application interface provided to facilitate APP to operate App Menu.
it's easy to set About, Preferences, and customized menus,
only the LCL TMenuItem is needed to pass in.
and we can control whether Cocoa is needed to automatically add
Hide, Hide Others, Show All, and Quit menu items.

Code: Pascal  [Select][+][-]
  2. Uses
  3.   CocoaMenus;
  4. var
  5.   item1: TMenuItem;
  6.   item2: TMenuItem;
  7.   item3: TMenuItem;
  8. begin
  9.   macOS_AppMenuIntf.aboutItem:= item1;           // About
  10.   macOS_AppMenuIntf.preferencesItem:= item2;     // Preferences...
  11.   macOS_AppMenuIntf.customMenus:= item3          // any custom menu items
  12.   macOS_AppMenuIntf.dontAutoCreateAppMenuItems:= True; // disable auto App Menu
  13. end;
  14. {$ENDIF}
« Last Edit: May 28, 2024, 07:02:35 am by rich2014 »


  • Hero Member
  • *****
  • Posts: 679
    • Tweaking4All
Hi Rich 😊

Apologies for not responding earlier, I do appreciate you Cocoa efforts!

Now ... It took me some time to figure out how to use the steps you described. Seems equally less intuitive as the old method. Which means, that whenever I need a menu, I'll need to go find this post and remember what I did, or consult the Wiki.

Is there any way we can incorporate this in the menu editor?
Or maybe in the object inspector (of a TMainMenu)?
Maybe adding these as properties of a TMainMenu (just like some of the "Restricted" properties we see with all controls)?

Anything I can do to help? (I'm not very familiar with the IDE code and such)

Just been tinkering some more, and manually creating a TMenuItem in code is not very RAD, is it?
« Last Edit: Today at 04:14:19 pm by Hansaplast »


TinyPortal © 2005-2018