UnicodeString literals are compiled wrong in ObjFpc mode on Windows
- Laz 2.2.3 / FPC 3.2.3 / Windows 7 Rus x64
- probably related: #34674 (comment 644748195)
- probably related: #40196
{$message _ 'АБВГД'}
- Forum: https://forum.lazarus.freepascal.org/index.php?topic=60718.new#new
Start new default LCL project in Lazarus, and put this code into it
procedure TForm1.FormClick(Sender: TObject);
var
a: ansistring;
sa, sc: unicodestring;
begin
a := 'ABCD БЮЖД ABCD';
sa := a;
sc := 'ABCD БЮЖД ABCD';
a := IntToStr(StringCodePage( a )) + ' / ' + IntToStr(StringElementSize(a)) + ' ' + a;
// ShowMessage(a);
sa := IntToStr(StringCodePage( sa )) + ' / ' + IntToStr(StringElementSize(sa)) + ' ' + sa;
// ShowMessage(sa);
sc := IntToStr(StringCodePage( sc )) + ' / ' + IntToStr(StringElementSize(sc)) + ' ' + sc;
// ShowMessage(sc);
ShowMessage(a + #13#10 + sa + #13#10 + sc);
end;
In Delphi it works fine, but in Lazarus the SC
is broken (but not SA
).
Forceful override (suggested in the forum) by {$modeswitch systemcodepage}
makes thing uniform (and uniformly broken).
The sources are in IDE default UTF-8
In the compiled EXE however we see two literals.
- One is correctly stored UTF-8 for
ansistring
. - Another is mis-converted UTF-16 for
unicodestring
. It either was erroneous "cp1251 -> UTF-16" conversion applied to UTF-8 sources, or it was UTF-8 sources unneededly and covertly converted to cp1251 before passed the "UTF-8 -> UTF-16" pipe.
Edited by Arioch The