I was going back through some code re-naming things to more appropriate names, as you do. So I decided to rename a CheckBox Caption to “TRIM & Analysis”. It doesn’t display correctly. It displays as: “TRIM _Analysis”
So then I checked further with replacing the ampersand with other non-standard characters, ie. "# + - ! % $ @, etc. etc… all those work fine, but not ‘&’.
Not a big deal, but annoying nonetheless.
I’m using 2016r3 on Windows 7.
[EDIT] Can someone else please have a go at replicating this.
I think the Caption of a Checkbox is using & as an accelerator Key marker, as we know them from Desktop Menus:
[quote]To designate the accelerator key, precede the letter by an ampersand ("&") in the menu or MenuItem Text property. For example, if you are creating a menu named “Actions” and you want to make the keyboard accelerator the A, you would enter &Actions in the Text property. To make the “t” the accelerator key, enter “Ac&tions”.
To display an ampersand in the menu, you need to double it like this: “&&”.[/quote]
Oh, I see. Well, it’s only complicated because of the Windows “keyboard shortcut” feature. I suppose Xojo could have implemented that with another property but they chose to do it with the “&” shorthand. Except for that, you wouldn’t have noticed it.
The nice thing about their preferred solution is that you are sure to pick a letter that appears within your text. If they had used a different property to specify the shortcut, the values could easily get out of sync and lead to unintended behavior. Chalk it up to an idiosyncrasy of the language.
BTW, the same holds true for menu captions. I try to add those wherever I can as a service to my Windows users. Use constants for the captions where you need to refer to them in code to avoid errors if you change the caption later. For example, if you set up a constant kCaptionTrimAndAnalysis = "&Trim && Analysis", you can set the caption of the checkbox to “#kCaptionTrimAndAnalysis” and use code like if cb.Caption = kCaptionTrimAndAnalysis then ....
I didn’t realize that. I suppose what’s unique then, given Xojo’s cross-platform nature, is that the caption is translated the same way on the Mac even though there is no keyboard shortcut.