Hi *,

I would like to have source file in Windows-1250 encoding, where are stored literal strings like 'áéíóčž' in Windows-1250 encoding (I share this one file between FPC/Lazarus and Delphi 7). Windows-1250 is also ANSI code page of my Windows OS. In source file I have:

{$IFDEF FPC}
  {$CODEPAGE cp1250}
{$ENDIF}
A pure string constant will still have CP_ACP as code page (which in Lazarus will by default mean UTF-8) also when you declare it as a typed String constant. The $CodePage directive will only influence the binary encoding of the string.

*and probably this is something non intuitive for me. Also after reading https://wiki.freepascal.org/FPC_Unicode_support#String_constants it is hard to understand for me. After reading "The compiler has to know the code page according to which it should interpret string constants, as it may have to convert them at compile time." my expectation is, that when I explicitly define encoding of source file by using **{$CODEPAGE cp1250} then compiler will be aware of string encoding in that file and will handle it appropriate. Now it works in another way which is not clear to me ... can it be better explained in wiki (any example)?*

*
*

What you need to do is the following:

type
  String1250 = type String(1250);

const
  MyString: String1250 = 'áéíóčž';

This way the string itself will have code page 1250 and if you assign to a normal String or a UnicodeString the compiler will insert the appropriate conversions.

*yes, this I can understand, but it will not work in Delphi 7 ...*

*TIA*

*L.*


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to