3

I'm trying to assign the Tricolon Unicode character #$205D as the caption to a button in a Lazarus Windows program like this:

MyButton.Caption := #$205D;

It works, the button displays the Tricolon fine, but the compiler emits the warning "Warning: Unicode constant cast with potential data loss".

How do I correctly assign the Tricolon character to the caption of an LCL control to get rid of the warning?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
dummzeuch
  • 10,975
  • 4
  • 51
  • 158

2 Answers2

3

LCL uses UTF8 encoding but #$205D is UTF16 character constant. So use UTF8 encoded constants instead:

const
    CTricolon = #$E2#$81#$9D;
    //CTricolon = '⁝'; // Also works fine if using character(s) as is in the source

...

    MyButton.Caption := CTricolon;
Abelisto
  • 14,826
  • 2
  • 33
  • 41
1

The problem is that the detection of a 2-byte -> (default) 1-byte conversion is compiletime, and the exact codepage of the default 1-byte type is runtime.

(either varying Windows encodings depending on locale or set to UTF8 on startup in Lazarus)

The compiler is warning you that this is dangerous. To fix it set the source encoding to utf8 and assign an utf8 string.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89