5

When you create a Delphi project and add a combobox and set ComboBox1.Items.Add('Zebra & Zulu') it shows "Zebra & Zulu" when you dropdown the list. Perfect.

When you create a Firemonkey project and add a comboxbox or comboedit and set ComboBox1.Items.Add('Zebra & Zulu') or ComboEdit1.Items.Add('Zebra & Zulu') it shows "Zebra Zulu" (no ampersand shows) when you dropdown the list. However, when you select it using the comboedit the text field part shows "Zebra & Zulu". Just weird.

Now there is a work around (sort of) but to me it is questionable. Add a second ampersand and the dropdown list shows the ampersand. However, adding the second ampersand shows up on the comboedit text field part. Bad.

My question is can you force these combo controls dropdown list to show the ampersand? And why is the ampersand missing in the first place?

t j
  • 413
  • 1
  • 7
  • 12

1 Answers1

2

This seems to be inbuilt behaviour that is likely leftover from the VCL's accelerator key handling. There does not seem to be a way to modify this behaviour with styles or options :

procedure TTextControl.DoChanged;
var
  TextStr: string;
begin
  if Assigned(FITextSettings) then
    FITextSettings.TextSettings.BeginUpdate;
  try
    if Assigned(FITextSettings) then
      FITextSettings.TextSettings.Assign(ResultingTextSettings);
    TextStr := DelAmp(Text);  // **!  Here deleting ampersands unconditionally

    if Assigned(FTextObject) then
    begin
      UpdateTextObject(FTextObject, TextStr);

   // ... etc - method continues

One workaround is to use the unicode full-width ampersand :

 ComboBox1.Items.Add('Zebra & Zulu');

Obviously not appealing for a number of reasons.

From the code above, this naturally affects all FMX TTextControls - even a TLabel, for example, will not display an ampersand when assigned :

 Label1.Text := 'Zebra & Zulu';

Even in a VCL application, for interest, this:

  Label1.Caption := 'Zebra & Zulu';

will render as

Zebra _Zulu

Although a VCL TComboBox will correctly render an item with a single ampersand...


This is an open QC, albeit one that does not appear in any hurry of being addressed :

http://qc.embarcadero.com/wc/qcmain.aspx?d=122564

J...
  • 30,968
  • 6
  • 66
  • 143
  • 1
    Yep, typical Embarcadero. Never gets fixed. – t j May 14 '15 at 17:47
  • Note that [QualityCentral has now been shut down](https://community.embarcadero.com/blogs/entry/quality-keeps-moving-forward), so you can't access `qc.embarcadero.com` links anymore. If you need access to old QC data, look at [QCScraper](http://www.uweraabe.de/Blog/2017/06/09/how-to-save-qualitycentral/). – Remy Lebeau Jun 09 '17 at 18:01