[fpc-pascal] FPC Unicode / CodePage aware strings

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Thu Dec 10 11:18:54 CET 2015


On 2015-12-10 09:50, Jonas Maebe wrote:
> 
> Graeme Geldenhuys wrote on Thu, 10 Dec 2015:
> 
>> Is there some white paper, blog post, awesome MvC article that explains
>> it all. And how it compares to Delphi's Unicode support (if this is
>> important - though I don't use Delphi at all any more).
> 
> http://wiki.freepascal.org/FPC_New_Features_3.0#Support_for_codepage-aware_strings

Thanks, but here's the problem. The wiki says FPC 3.0 is now Delphi 2009
string compatible. So I starting reading the "Delphi_and_Unicode.pdf"
white paper. I tried the first example shown on page 7 (code below):

var
  ch1: Char;
  ch2: AnsiChar;
begin
  ch1 := 'ù';   // error
  Memo1.Lines.Add ('WideChar');
  Memo1.Lines.Add ('UpCase ù: ' + UpCase(ch1));
  Memo1.Lines.Add ('ToUpper ù: ' + ToUpper (ch1));  // warning
  ch2 := 'ù'; // error
  Memo1.Lines.Add ('AnsiChar');
  Memo1.Lines.Add ('UpCase ù: ' + UpCase(ch2));
  Memo1.Lines.Add ('ToUpper ù: ' + ToUpper(ch2)); // warning
end;


Tried to compile that with FPC (yes, I included the new "Character" unit
in uses clause) and I get a couple of compiler errors. I tried first
with mode OBJFPC and then with mode DELPHI. Same compiler errors.


Compile Project, Target: project1: Exit code 1, Errors: 3, Warnings: 2
project1.lpr(35,10) Error: Incompatible types: got "Constant String"
expected "Char"
project1.lpr(38,50) Warning: Implicit string type conversion with
potential data loss from "WideString" to "AnsiString"
project1.lpr(39,10) Error: Incompatible types: got "Constant String"
expected "Char"
project1.lpr(42,50) Warning: Implicit string type conversion with
potential data loss from "WideString" to "AnsiString"
project1.lpr(54,13) Error: Variable identifier expected


So already it seems information is missing for FPC usage, or FPC clearly
isn't as "delphi compatible" as the wiki makes out to be. Or something
else went astray.  This is exactly what I'm talking about. It clearly
doesn't "just work". I'll read the FPC_Unicode_support wiki from top to
bottom. Maybe that sheds some light.

My test project was created using Lazarus (Project -> New Application).
 I tried the same using a fpGUI toolkit project too.



Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp



More information about the fpc-pascal mailing list