Recent

Author Topic: [CLOSED] TEdit: & (Ampersand) gets deleted  (Read 174 times)

wittbo

  • Jr. Member
  • **
  • Posts: 95
[CLOSED] TEdit: & (Ampersand) gets deleted
« on: February 14, 2020, 01:38:36 pm »
This morning I got a really enerving problem:
I want to edit a string, that contains some ampersand chars. My program code makes some declarations like:
    s := 'example&name&surname'
    edit1.text := s
Upon doing this, all ampersands get deleted and the text in the edit field is without any ampersands.

When i duplicate all ampersands before writing the string into the edit field:
   s := 'example&&name&&surname'
all double ampersands are replaced by one single ampersand in the tedit field.

What could/should I do to realize a standard editing solution including strings with ampersand chars?
 
« Last Edit: February 14, 2020, 02:58:47 pm by wittbo »
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.0.6
iMac with MacOS 10.13.6 / Lazarus 2.0.2

lucamar

  • Hero Member
  • *****
  • Posts: 2383
Re: TEdit: & (Ampersand) gets deleted
« Reply #1 on: February 14, 2020, 02:22:18 pm »
Can't reproduce in Linux; it might be an OS dependent artifact or a bug that makes it process Text (which is a TCaption rather than a plain String, though it shouldn't matter) the same way it does for a labels, buttons, menu items, etc. where "&" is used to signal the "shortcut" letter in the caption (the one underlined).

A workaround to correct it is to code a specialized function to set the text for edit controls, something like:

Code: Pascal  [Select]
  1. procedure SetEditText(const AnEdit: TEdit; const Value: String);
  2. begin
  3.   if Assigned(AnEdit) then
  4.     AnEdit.Text := StringReplace(Value, '&', '&&', [rfReplaceAll]);
  5. end;

which you would use instead of assigning directly to TEdit.Text:

Code: Pascal  [Select]
  1.  {Instead of:
  2.   edit1.text := 'Tom & Jerry';
  3. we'll do: }
  4.   SetEditText(Edit1, 'Tom & Jerry');
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

wp

  • Hero Member
  • *****
  • Posts: 6707
Re: TEdit: & (Ampersand) gets deleted
« Reply #2 on: February 14, 2020, 02:57:27 pm »
Can't reproduce in Linux.
Can't reproduce on Windows either. Probably one more of there mysterious Mac bugs (if I interpret your signature correctly).
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wittbo

  • Jr. Member
  • **
  • Posts: 95
Re: TEdit: & (Ampersand) gets deleted
« Reply #3 on: February 14, 2020, 02:57:41 pm »
It seems to be an artefact.
iMac 2011, macOS 10.13.6, Lazarus 2.0.2:   Error occurs as described
MB Air 2014, macOS 10.14.6, Lazarus 2.0.6:  works as expected, no error

So, maybe it's the macOS version or the Lazarus version.
I will close this defect.
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.0.6
iMac with MacOS 10.13.6 / Lazarus 2.0.2