[Lazarus] Converting all code to use UnicodeString

Sven Barth pascaldragon at googlemail.com
Mon Sep 25 23:23:01 CEST 2017


On 25.09.2017 23:11, Marcos Douglas B. Santos via Lazarus wrote:
>>> [...]
>>> I know almost nothing about compilers. But IMHO, the compiler should
>>> have which it already have: "string", which is an alias.
>>> Then, for each OS, we should pass one argument like (simplifying):
>>> -S=UnicodeString  or -S=AnsiString... something like that (I hope you
>>> understood).
>>
>> The flags are -MDelphiUnicode, -MDelphi or -MObjFPC.
>> But they only compile the units with sources in the unit path, which
>> excludes all FPC units. Also keep in mind that the system unit and the
>> RTL require a lot of low level functions, which require separate
>> versions.
> 
> Which make this flags useless for that. It should be all code (my,
> RTL, Lazarus, etc) to make this work using one type of string.

No, because especially the RTL and FCL is usually provided precompiled.
Thus you can't change the string type anymore afterwards without
recompiling all the code.

>> Unicode <> UnicodeString
>> Unicode is working with UTF-8.
>> If you want a Delphi compatible UTF-16 RTL and packages you are welcome
>> to help the FPC team.
> 
> I can help in a high level way (Classes, Components, etc) not in the
> compiler level.
> But how can I know about these tasks? May I just pick one in bug
> tracker that I want? How to know who is working on each task, which is
> more important?

Currently noone is working on it.

A first step would be to add modeswitch headers to all units that must
not use a specific mode (e.g. the System, ObjPas and some more language
support units) like this:

=== code begin ===

{$ifdef FPC_UNICODE_RTL}
{$modeswitch unicodestrings}
{$endif}

=== code end ===

Once this is done one can test to compile the RTL, FCL and packages with
FPC_UNICODE_RTL defined and see what blows and fix that step by step...

Alternatively a constant in the System unit might be better so that one
can check like this:

=== code begin ===

// System unit
{$ifdef FPC_UNICODE_RTL}
FpcRtlIsUnicode = true;
{$else}
FpcRtlIsUnicode = false;
{$endif}

// some other unit
{$if FpcRtlIsUnicode}
{$modeswitch unicodestrings}
{$endif}

=== code end ===

Or if one wants to compile with -Municodestrings than instead the core
units need to be protected with

=== code begin ===

{$modeswitch unicodestrings-}

=== code end ===

I'm currently not sure what would be the better approach in the long
term... :/

Regards,
Sven


More information about the Lazarus mailing list