Delphi Menu AutoHotkey Issue

With most Delphi components, when you write a value to a property, that is what you get when you later read that property.

However, this is not the case with the Menu captions - sometimes, what you read and what you write are NOT the same. Specifically,

However, if you do something to display the menu (such as right click and pop it up) ... then the caption MAY have changed. Specifically, if the first letter of the text (in this example - T) was not already associated with a keyboard shortcut, then the ampersand would be added in front of it ... otherwise, it would be added in front of the first unused letter. In addition, if some Asian language flag was set, then the parentheses would also be added.

On the other hand, if you originally set the caption to 'T&est', then there would be no change.

My complaint is not that this is incorrect behavior - instead, my complaint is that this is undocumented behavior.


Workaround

I discovered this because I wanted to use the menu caption to decide what function to perform. Of course, I could have just bitten the bullet and hard coded an ampersand. However, there are 2 built-in functions to handle this problem This is one possibility.


Mechanism

The caption modification occurs when InternalRethinkHotkeys is called as part of the popup process. By default, each menu item's AutoHotkeys is set to maParent and the popup menu's AutoHotkeys is set to maAutomatic. As a result, Delphi is performing as designed and ampersands are automatically added to the captions.

My problem is that the help does not say any of this.

In addition, none of the related See Also links point to either of the functions used to solve this problem.

There is no excuse for this behavior not being described in the help file.


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / Delphi / MenuAutoHotkey.html