[fpc-pascal] String literals and code page of .pas source file

Mattias Gaertner nc-gaertnma at netcologne.de
Tue Sep 8 22:32:09 CEST 2020


On Tue, 8 Sep 2020 20:27:20 +0200
Jonas Maebe via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:

> On 07/09/2020 08:51, LacaK via fpc-pascal wrote:
> 
> > attached simple Lazarus compilable project (one Form).
> > 
> > ...
> > type
> >   String1250 = type AnsiString(1250);
> > 
> > const
> >   c2: AnsiString = 'áéíóčž';
> >   c3: WideString = 'áéíóčž';
> >   c4: String1250 = 'áéíóčž';
> > 
> > { TForm1 }
> > 
> > procedure TForm1.FormShow(Sender: TObject);
> > begin
> >   label1.Caption:='áéíóčž'; // FAIL
> >   label2.Caption:=c2;       // FAIL

label2.Caption:='a'+c2; // OK

> >   label3.Caption:=c3;       // OK
> >   label4.Caption:=c4;       // FAIL
> > end;  

Reason is that LCL TLabel.Caption expects UTF-8.
You can use 

label2.Caption:=WinCPToUTF8(c2); // from unit LazUTF8

Maybe SetCaption could check if passed string is not CP_ACP and do a
conversion.

 
Mattias


More information about the fpc-pascal mailing list