[Lazarus] Lazarus (UTF8) and Windows: SysToUTF8, UTF8ToSys... Is there a better solution?

Juha Manninen juha.manninen62 at gmail.com
Sat Dec 21 16:18:05 CET 2013


On Sat, Dec 21, 2013 at 4:33 PM, Marcos Douglas <md at delfire.net> wrote:
> That's it!
> I think you talking about of new versions of Delphi, right? So I
> always read that "new Unicode implementation" in new versions of
> Delphi is wrong, broke things, etc. but you is writing other vision.

Yes, Delphi 2009+. Delphi 2009 is soon 5 years old, not really new any more.
IMO it does a good job for such a fundamental change in string type.
Only code that relies on "sizeof(char) = 1" does not work. It includes
streaming strings, file I/O or I/O with some outside devices, using
Length(Str) as a parameter for GetMem(), Move() etc.
Most "clean" code works amazingly well, if you are ok with using
UTF-16 everywhere.


> These conversions, IMHO, could be automatic -- as Delphi does -- when
> I use the correct type of string, in that case UT8String. So, I can
> write my packages and opt to use only UTF8String or UTF16String in all
> arguments and the compiler convert for me. What is wrong in that
> approach?

Nothing wrong I guess. I hope it will be possible with FPC. Still,
let's not speculate more, we already have such mail threads in fpc-dev
list that continued for months.


> If you do not want automatic conversions, use the RawByteString type.
> Delphi does not do conversions in that case, right?
> Thank you, I'm learning.

You can bypass the conversion sometimes by using RawByteString but it
would be rather hackish. Remember, all VCL classes and string
functions expect UTF-16. I don't want to try what happens if you pass
them a UTF-8 encoded string using some hack.
The bottom line is: Use only UTF-16 with Delphi and it works very well.


> For example, I use a lot PostMessage, SendMessage, PeekMessage... Are
> these cross-plataform? If not, how can I do the same?

LCL (and VCL) typically use events, like TNotifyEvent. They are
basically just call-back functions.

Juha




More information about the Lazarus mailing list