[Lazarus] API-Import of "PUTF8Char"

Martok listbox at martoks-place.de
Sun Sep 4 15:56:49 CEST 2016


Okay, that's pretty much what I thought, thanks.

However:
> The other way round - assigning a string to a PChar - is not supported
> by FPC. So only with LazUTF8 you can use a simple type cast. Without
> LazUTF8 you must convert the string first, before type casting.
This does not work either, assigning a UnicodeString to a PChar simply does
nothing, as if PChar was CP_NONE...

This works as expected and is effectively the same as calling UnicodeToUTF8()
directly:
  pc:= PChar(UTF8String(UniStr));

If there is no conversion at all that would be okay too, but if not I would have
to define PUTF8Char = PByte or something just to be safe.

> Alternatively you can use a more optimized version in case LazUTF8 is
> used:
> 
> procedure SetUserID(const NewValue: AnsiString); 
AnsiString? Why would that help?


>> Is there a good way to do what I want, or would it be easier to use PUnicodeChar
>> and pass the strings as UTF-16? How well would other languages work with that?
> 
> Whether it's easier totally depends on the other language.
Well, people with Windows experience will probably expect a wchar_t * as UCS-2
or UTF-16, but in contrast Rust would work far better with UTF-8 (because that's
their native string type).

>From your code examples I think I didn't mention one thing: the internal fields
are all UnicodeString. This question is just about the external
(non-pascal-facing) interface and how to design it without having to use
explicit Utf8ToUnicode everytime.


Regards,

Martok



More information about the Lazarus mailing list