Unable to get ampersand (&) to display in a Delphi TActionMainMenuBar
Asked Answered
P

1

30

I am in need of help trying to get the ampersand character to show up in a Delphi XE6 VCL TActionMainMenuBar. I have come across similar requests on Stack Overflow but none that directly address the problem I am having.

When creating an action in the TActionManager, I need the caption of an action to read Network & Database. I have tried using two ampersands in the caption Network && Database to escape the accelerator which did not work. When I included two ampersands, I ended up with Network _Database (See Screenshot1). I have also set the property of ActionBar > Items > AutoHotKeys to false and ActionMainMenuBar > PersistentHotKeys to false. Doing so did not rectify the my issue.

Screenshot1

The one thing I did try out of pure desperation that I thought fixed it was to include four ampersands Network &&&& Database which when ran showed up as Network & Database (See Screenshot2). However during testing, if I were to press Alt to turn on hotkeys and navigate into the menu, the caption of the action would read Network && Database. I tried to include a screenshot of this however since I have less than 10 reputation points Stack Overflow limits my post to two attachments.

Screenshot2

If anyone can point me in the right direction of if I have left out some information please let me know. I've run out of ideas on how to fix this and I cannot come across anything similar when searching Google. Thanks in advance for the help.

Philter answered 1/2, 2017 at 22:5 Comment(10)
Vote.Ritualize
Is it really that important to display & ? Why not simply use Network and Database or Network / Database ? I've just had a look through the menu items in a few apps (Notepad++, Visual Studio, just for example) and have yet to see anything other than A and B. No & anywhere. Perhaps you're fighting a battle that others have already decided just isn't worth it ? :)Hartford
@Hartford It's only a battle because the RTL and VCL screw it up. System menus can do this.Vada
The linked QC entry for this bug contains a workaround.Somerville
@Hartford if it was up to me I would have to agree with you and just replace the ampersand with the word and. Unfortunately I was tasked to figure this out by my superior.Philter
@Somerville Thank you for the link. Very much appreciated. I will go ahead and give it a try and see how it works out. Again, thank you.Philter
The code in the linked QC entry did resolve my issue. Surprised (not really) its still present in Berlin. @SertacAkyuz I didn't see your comment at first but I upvoted it. Thank you all for the help. This was driving me crazy.Philter
@Philter - Yeah, it is a short comment, easy to miss. ;) You're welcome.Ritualize
@David - the reason for a battle doesn't alter the fact that a battle is having to take place. One can only presume that the project manager of this particular project is in the luxurious position of not having any more important things to have their developers spend time on. If only we were all so lucky. :) But unless Notepad++, Visual Studio etc are all using the Delphi RTL/VCL there would appear to be other reasons for not using & in menus, even where there is no battle (or the battle perhaps remains, but for other reasons).Hartford
FYI: probizwriters.com/PBW-blog/index.php/ampersand-usage (short version: & is not simply an alternative to/replacement for and)Hartford
T
2

You can fix it on your form's onshow event

action3.caption := 'Network &&Database';
Thormora answered 12/4, 2017 at 4:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.