However, this is not the case with the Menu captions - sometimes, what you read and what you write are NOT the same. Specifically,
MenuItem1.Caption := 'test'; s := MenuItem1.Caption ; // This returns the value that was writtenHowever, if you do something to display the menu (such as right click and pop it up) ... then the caption MAY have changed.
s := MenuItem1.Caption ; // This returns 'test', '&test', 'te&st', '(&)test' ...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
s := MenuItem1.Caption ; // This returns 'test', '&test', 'te&st', '(&)test' ... if s = '&Test' then ... if s = '&Read' then ...However, there are 2 built-in functions to handle this problem
s := MenuItem1.Caption ; // This returns 'test', '&test', 'te&st', '(&)test' ... if AnsiSameCaption(s, 'test') then ... if AnsiSameCaption(s, 'read') then ...
Mechanism
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