Run Time Sub Menu Gap

Hi all,
In my Delphi XE application I have a main menu and some of the menu items have a sub menu.

The sub menus that are created at design time are aligned to the parent menu item correctly, but the ones I create in code always have a gap between the menu item and the sub menu.

Is there some other property of the sub menu items I need to set apart from owner and parent to get them to display correctly?

Current code:

procedure TfmMain.UpdateHelpMenu;
  MI: TMenuItem;
  x: Integer;
  while mnShortcutList.Count > 0 do
  for x := 0 to Prefs.Shortcuts.Count-1 do
    if Prefs.Shortcuts[x].Key <> 0 then
      MI := TMenuItem.Create(mnShortcutList);
      MI.Caption := Prefs.Shortcuts[x].HelpCaption;
      MI.ShortCut := Prefs.Shortcuts[x].Shortcut;
      MI.ImageIndex := 79;


You said you’re using Delphi XE, can we assume that screenshot is from a Win10 machine?

I tried similar code using Delphi Sydney on both Win7 and Win10 without seeing a problem.

I dug out an old Delphi XE VM and gave it a go running on both WinXP and Win10 but still couldn’t replicate it.

My sample doesn’t have images on the menu items. If you don’t assign the images to the sub menu items do you see the same result?

Yes, Windows 10. No difference if the image is not set.

I did find that I’m using the TAdvMainMenu from TMS and that’s where the issue is.

If I use a plain TMainMenu it draws correctly.

Something else I noticed with the TMS menu is that the drawing style of the design time sub menus are correct, but the run time versions look plain by comparison.

I checked the form code and the TMS menu is using TMenuItem for the design time objects so not sure why they behave differently at run time.

I’ll ask TMS.

Perhaps try changing

MI := TMenuItem.Create(mnShortcutList);


MI := TAdvMenuItem.Create(mnShortcutList);

assuming that there is such a class.

No such class I’m afraid. It will be interesting to see what TMS come back with.

I swapped out my TMainMenu for a TAdvMainMenu and I can replicate it now.

You have to wrap your menu item changes in calls to TAdvMainMenu.BeginUpdate and TAdvMainMenu.EndUpdate.

1 Like

Excellent ! Thank you so much. :slight_smile:

1 Like

Although I am using TMS FNC in FMX, as a general rule I find that BeginUpdate and EndUpdate are important to get things to work as expected.

It was interesting in that the TAdvMainMenu (which descends from TMainMenu) actually introduced the BeginUpdate/EndUpdate methods. They don’t exist on the ancestor TMainMenu, so they’re easily missed by those used to the standard menu components.

@David_Duffy you must have felt at home in TMS support Discourse forum. :grinning_face_with_smiling_eyes:

I’m finding the new ADUG forum much better than the old list.

Thanks to all those that made it happen. :slight_smile: