2
votes

In a Delphi 2007 program I am using a TMainMenu referencing actions in a TAction list. I have prefixed the hotkeys of all main captions with an ampersand:

&File | &Edit | Ev&aluate | ...

In design view these hotkeys are underlined as I would expect, but when I start the program they no longer are underlined but they work nonetheless. In contrast to this, for all the submenu icons

  &File
  &New ...
  &Open ...

the underline is shown as expected.

I am aware of the Windows pisplay properties option "Hide underlined letters or keyboard navigation until I press the Alt key." and have disabled it. In all other programs this works fine, including the Delphi IDE.

If I create a new VCL appliation and just add a TMainMenu and a few menu items, it works as expected.

This has me baffled, really.

Is there any property of the TMainMenu component or maybe an application option that I must change? The "Enable runtime themes" project option is grayed out for some reason, might that be the problem? If yes, what causes this?

5
Similar possible duplicate question: stackoverflow.com/questions/280247/…stukelly
No, it's different. I already checked the Windows setting.dummzeuch
If you're talking about the Windows setting: "Hide Underlined Letters for Keyboard Navigation until I Press the Alt Key", mine was also unchecked (i.e. disabled). See my answer below.lkessler

5 Answers

2
votes

This may not be a Delphi issue. I have just tried this with IE8 on WinXP. On my machine, with the display properties set to require the Alt key, the underlining works as expected. However, with the checkbox unchecked, the underlining never appears on the main menu items (even when using the Alt key), but always appears on the File,Edit,View etc submenus (as you describe) ........ unless Microsoft wrote IE8 in Delphi :-)

1
votes

I asked the same question last year and there were some excellent answers: Menu Accelerator Keys Not Showing Up Delphi 2009

In conclusion, it appears to be a Delphi bug, and I reported it to Embarcadero at: http://qc.embarcadero.com/wc/qcmain.aspx?d=68816

However, they have no resolution to it, so unless others (maybe you) also complain, I don't expect it will get addressed.

Step's answer to my question refers to a possibly related bug reported on the Delphi forums: ALT Key press causes controls to disappear under Themes in Vista and XP. This one is marked as "resolved" with several possible fixes listed in the comments. I have not had the opportunity to go through these.


By the way, since I asked that question last year, I got a new computer with Vista. The same problem still happens, even when the Vista Ease of Access Centre setting: "Underline keyboard shortcuts and access keys" is set. So the Delphi bug still exists.

I was very surprised to find the default was that this was unchecked. I guess in Vista, they want a cleaner looking menu with the assumption that not many people ever used the accelerator keys.

1
votes

The easiest way to fix this problem seems to use TJvMainMenu from the jvcl instead of TMainMenu. I tried the current version 3.38, but it is possible that the problem was fixed already in earlier versions. Since I was using the jvcl anyway it does not add much to my program's size. Your mileage may vary though, the jvcl is a huge library.

0
votes

Uses an empty image list for main menu, if it is possible. In this way you can force delphi to paint menu correctly. (But looks ugly in vista and w7)

0
votes

Are you sure you don't have OwnerDraw set to true in the MainMenu?