[Lazarus] Converting all code to use UnicodeString

Marcos Douglas B. Santos md at delfire.net
Tue Sep 26 03:37:43 CEST 2017


On Mon, Sep 25, 2017 at 9:52 PM, Juha Manninen via Lazarus
<lazarus at lists.lazarus-ide.org> wrote:
> On Tue, Sep 26, 2017 at 3:14 AM, Marcos Douglas B. Santos via Lazarus
> <lazarus at lists.lazarus-ide.org> wrote:
>> So, you mean that I cannot declare a constant without specify the
>> type. The language allow me but it won't work?
>
> Yes you can declare a string constant without specifying the type.

But according with this table, I shouldn't do that because so many
problems could happen.
http://wiki.freepascal.org/Unicode_Support_in_Lazarus#Without_.7B.24codepage_utf8.7D_or_compilerswitch_-FcUTF8

>> 3.1. "When a parameter type is a pointer PWideChar,
>> you need a temporary UnicodeString variable.
>> ...
>> That is a ugly hack. This code doesn't make any sense, if you don't
>> know about these Unicode issues.
>> We need do remember that trick when we are coding... not good.
>
> It is not so ugly. It is actually an elegant solution. Just one
> assignment, using the FPC's automatic conversion in a clever way. No
> explicit conversion functions or anything.
> The "ugly" pointer typecast is needed always, also in Delphi.

The "ugly" is because we need to remember to do that instead of just
assign the variable.
IMHO, both design are wrong. But I understand that the problem is in
the compiler — or RTL.

>> 4. "Reading / writing text file with Windows codepage"
>> ...
>> The text said: "This is not compatible with Delphi ".
>> Examples on that page are hacks.
>
> The solution is to NOT use Windows codepages. They can be seen as a
> historical remain with severe inherent problems which are solved by
> Unicode already a long ago.
> Windows has supported full Unicode since year 2000, and supported
> UCS-2 before that.
> Why would anybody still use the historical Windows codepages?

So, no problems here and the page is outdated. OK.

>> Summary:
>> I know that was a huge work for who made that. Lazarus is more
>> Unicode, more compatible with Delphi, and the team could move on.
>> Great.
>> But you might agree with me that this is far from a good design, right?
>
> IMO it is not far from a good design. From FPC's point of view it is a
> hack but you can write 100% Delphi compatible code by following just
> few simple rules (and dumping the historical Windows codepages).

Like I said, it's a hack. But, again, it was|is a great job. No doubt.

Best regards,
Marcos Douglas


More information about the Lazarus mailing list