Checkbox caption is not happy with Ampersand "&"


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.

Please try it with TRIM && Analysis.

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]

YES indeed!, it worked by your double ampersand method. Thanks Sascha. :slight_smile:

So taking it further, if I wanted to refer to the object via its caption, would I use “TRIM && Analysis” ?

Can’t test it right now, but i would say “Yes” :slight_smile:

Yep cheers Sascha.

I doubt if ever I would require that scenario, and have not tested it myself, but the question had to be asked.

If you want to add a key shortcut, use another ampersand to indicate it, like “&Trim && Analysis” or Tr&im && Analysis".

Now that’s just doing my head in Kem :slight_smile:

Let’s please remember that this thread is about my issues with changing the name of a checkbox caption. Nothing more, nothing less.

Um… ok?

Sorry Kem if I don’t make sense.

What I’m trying to get at is that I was suprised that a seemingly innocuous re-naming of a caption/text could be so complicated.

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 ....

The ‘&’ is the sanctioned way to do it in all Windows supported languages. It is absolutely not unique to Xojo.

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.

Indeed it seems strange that Xojo would implement a specifically Windows feature over Mac. Maybe to avoid cross platform issues ?

Must be. Now imagine the issues we’d face if they hadn’t. :slight_smile: