How to prevent "unicode constant cast with potential data loss" warning in Lazarus?

I am trying to assign the Tricolon Unicode character # $ 205D as the title of a button in a Windows Lazarus program like this:

MyButton.Caption := #$205D;

      

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

How do I properly assign the Tricolon symbol to the header of the LCL control to get rid of the warning?

+3


source to share


2 answers


LCL uses UTF8 encoding, but # $ 205D is a 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;

      

+3


source


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

(either changing the Windows encoding depending on the language, or setting UTF8 on startup in Lazarus)



The compiler warns you that this is dangerous. To fix this, set the original encoding to utf8 and assign the string to utf8.

+1


source







All Articles