Storing UTF8 string in a UnicodeString
Posted
by Mick
on Stack Overflow
See other posts from Stack Overflow
or by Mick
Published on 2010-04-23T10:38:45Z
Indexed on
2010/04/23
10:43 UTC
Read the original article
Hit count: 628
In Delphi 2007 you can store a UTF8 string in a WideString and then pass that onto a Win32 function, e.g.
var
UnicodeStr: WideString;
UTF8Str: WideString;
begin
UnicodeStr:='some unicode text';
UTF8Str:=UTF8Encode(UnicodeStr);
Windows.SomeFunction(PWideChar(UTF8Str), ...)
end;
Delphi 2007 does not interfere with the contents of UTF8Str, i.e. it is left as a UTF8 encoded string stored in a WideString.
But in Delphi 2010 I'm struggling to find a way to do the same thing, i.e. store a UTF8 encoded string in a WideString without it being automatically converted from UTF8. I cannot pass a pointer to UTF8 string (or RawByteString), e.g. the following will obviously not work:
var
UnicodeStr: WideString;
UTF8Str: UTF8String;
begin
UnicodeStr:='some unicode text';
UTF8Str:=UTF8Encode(UnicodeStr);
Windows.SomeFunction(PWideChar(UTF8Str), ...)
end;
Any help appreciated. Thanks.
© Stack Overflow or respective owner