3

I have a Delphi 10.4.2 program (32-bit) where menu items are added during program load (the Application.OnActivate event, coded to run only once). Without a vcl style the new items are displayed correctly, however when a style is applied (such as the very nice Iceberg Classico in the screenshot) the display is not correct. The menu options are there, and can be clicked on; but the text and the icon are not drawn.

screenshot showing blank menu options

Any workrounds? I'm assuming that it’s because those particular menu options are added after the style is applied. Is there a way to refresh the style?, or am I missing a setup property when creating the menu items?

Thanks.

Edit: Yes, the 'File' menu and sub menu items are displayed correctly. Code that creates the new menu and items (simplified) is:

procedure TDbHelper.CreateHelpMenu;
// Called by OnApplicationActivated event, and run just once 
var
   aMenu: TMainMenu;
   mnHelp, mnItem: TMenuItem;
   idx: Integer;
begin
   aMenu := Application.MainForm.Menu;
   // create new menu
   mnHelp         := aMenu.CreateMenuItem;
   mnHelp.Name    := 'WISHelp1';               
   mnHelp.Caption := 'WIS Help';
   aMenu.Items.Add(mnHelp);
   // now the submenu items
   for idx := 0 to HelpLinks.Count - 1 do
   begin
      mnItem := TMenuItem.Create(mnHelp);
      mnItem.Name := HelpLinks[idx].Key;
      mnItem.Caption := HelpLinks[idx].Text;
      mnItem.ImageIndex := HelpLinks[idx].ImageIndex;                            
      mnItem.OnClick := WISHelpItemClick;
      mnHelp.Add(mnItem);
   end;
end;
PhilW
  • 457
  • 6
  • 15
  • 2
    Are items in `File` menu shown correctly after adding of new items? Also it would be nice if you show a code example of how you are adding these new items to your main menu. – SilverWarior Dec 21 '20 at 11:24
  • @SilverWarrior thanks for the response; I have edited my question to provide the extra detail requested. – PhilW Dec 21 '20 at 16:56

2 Answers2

2

Finally decided to switch off the vcl styles for the menus. I followed the advice of RRUZ on another question and added a line to the dpr source so that it became:

  Application.Initialize;
  TStyleManager.TrySetStyle('Iceberg Classico');
  with TStyleManager do SystemHooks := SystemHooks - [shMenus];
  Application.Title :=  'blah, blah, etc'

The menu items have re-appeared, and they look fine:

screenshot showing unstyled menu options

Thank you to SilverWarior for their input and suggestions.

PhilW
  • 457
  • 6
  • 15
  • Using Delphi11 I have had a similar problem of empty menu items with a virtual image list used. Switching off [shMenus] restored the text but left the menu the wrong colour. Strangely, I am able to populate a popupmenu with a virtual imagelist, colour text and bitmaps all fine. – Mike Scott Feb 20 '22 at 11:28
0

Tried to recreate this scenario in Delphi 10.3 and it works fine for me.

But then with some fiddling I managed to recreate your "end result". And in order to do so I had to pass empty strings for mnItem.Name and mnItem.caption.

So I believe that the problem you are facing is not by using VCL Styles but in fact by your HelpLinks[idx].Key and HelpLinks[idx].Text methods returning empty strings. So you end up with menu items with no name and no caption therefore it appears as they are rendered wrong.

If I'm correct disabling VCL styles will still have same result.

SilverWarior
  • 7,372
  • 2
  • 16
  • 22
  • @SilverWarrior that's useful info, thanks. The idea of empty strings was checked, and as I mentioned in the question without a vcl style the new items are displayed correctly. BTW, I didn't downvote your answer, and I don't why anyone would do so; this forum can be a tough gig sometimes... – PhilW Dec 22 '20 at 10:57
  • If disabling VCL styles results in menu items being displayed correctly then I guess there might be some bug in VCL styles code that is present in Delphi 10.4 and not in Delphi 10.3. Since Delphi 10.4 introduced the ability to chose specific style for each component individually I'm guessing that in your scenario style information might be loaded to late and thus style graphics are rendered over the menu caption. Perhaps you should try to add menu item to your main menu first and then set its properties. This might force VSL styles to render said items correctly. – SilverWarior Dec 22 '20 at 12:40
  • Now I'm pretty sure there is a bug in newest VCL styles. Why? Another question about [problems using VCL styles in Delphi 10.4](https://stackoverflow.com/questions/65408970/painting-issue-of-panels-with-styles-when-using-doublebuffered-true) was just posted here on Stack overflow. By the looks of what is happening I'm guessing that newest VCL styles might be having problems with rendering order of specific styled objects. – SilverWarior Dec 22 '20 at 12:51