[Lazarus] String vs WideString

Marcos Douglas B. Santos md at delfire.net
Mon Aug 14 14:50:23 CEST 2017


On Sun, Aug 13, 2017 at 7:51 AM, Juha Manninen via Lazarus
<lazarus at lists.lazarus-ide.org> wrote:
> On Sun, Aug 13, 2017 at 1:21 AM, Bo Berglund via Lazarus
> <lazarus at lists.lazarus-ide.org> wrote:
>> So AnsiString is not safe either....
>
> That is a little misleading.
> Actually using the Windows system codepage is not safe any more.
> The current Unicode system in Lazarus maps AnsiString to use UTF-8.
> Text with Windows codepage must be converted explicitly.
> This is a breaking change compared to the old Unicode suppport in
> Lazarus 1.4.x + FPC 2.6.x.
> The right solution is to use Unicode everywhere. Windows codepages can
> be seen as a historical remain, retained for backwards compatibility.
> Now is year 2017, Unicode has been used for decades. Everybody should
> use it by now.

"The right solution is to use Unicode everywhere."
I agree. But would be best if the compiler uses Unicode everywhere and
us, developers, using just one type called "string"... Even if this
break the old code. Maybe, instead using "string", the new code should
be use just UnicodeString...

Well, I know that many people here already had this "fight" about
Unicode so, let's forget about it what the compiler "should" or not to
do.

> Marcos Douglas, please change the encoding in your text file to UTF-8.
> Every decent text editor, including the editor in Lazarus, has a
> feature to do it.
> Once the data is Unicode, it is all smooth sailing.
> Data is converted between UTF-8 and UTF-16 losslessly.

You're right.

> One more thing:
> Data for WideString/UnicodeString parameters in WinAPI functions are
> converted automatically. You can ignore the warning or suppress it by
> a type cast as Mattias showed.
> However for PWideChar parameters you should create an explicit
> temporary variable, usually UnicodeString but WideString for OLE.
> Assigning to it from your "String" data converts encoding.
> Then cast the new variable as the required pointer type.

This is a ugly trick... but I understood what you mean.

Best regards,
Marcos Douglas


More information about the Lazarus mailing list