[fpc-pascal] String literals and code page of .pas source file
Jonas Maebe
jonas at freepascal.org
Sat Sep 12 18:51:04 CEST 2020
On 12/09/2020 18:44, Sven Barth via fpc-pascal wrote:
> Jonas Maebe via fpc-pascal <fpc-pascal at lists.freepascal.org
> <mailto:fpc-pascal at lists.freepascal.org>> schrieb am Sa., 12. Sep. 2020,
> 17:47:
>
> > All the doubts, questions, and discussions prove that current
> system is
> > counter-intuitive and confusing.
>
> The issue in this thread is caused by a bug in the LCL: it blindly
> assumes that the dynamic code page of the caption string is always
> utf-8. That is simply wrong (unless you put the burden on the user to
> always assign an utf-8-encoded string to it, but _that_ is
> counter-intuitive and confusing).
>
>
> But shouldn't the compiler insert a conversion if the string is declared
> as CP_1250 and the destination is CP_ACP?
There are two things:
1) regardless of how the static code page of a string is declared, it is
never guaranteed that its dynamic code page will match it. The simplest
example is when you assign a RawByteString to it. There is, however,
also a second case (and this one indeed is counter-intuitive, but needed
for backward compatibility):
2) the second bullet under
https://wiki.freepascal.org/FPC_Unicode_support#Dynamic_code_page
That's what gets triggered here: the source file CP is CP_1250 and the
string is also ansistring(1250). That case would be solved by declaring
Label as UTF8String though.
Jonas
More information about the fpc-pascal
mailing list