WideString
is encoded in UTF-16 in all Delphi versions. It's a wrapper around the COM BSTR
. You simply cannot store UTF-8 content in a WideString
.
The data type that holds UTF-8 strings in pre-Unicode Delphi is UTF8String
, which is essentially just an AnsiString
. It is defined like so:
type
UTF8String = type string;
In pre-Unicode Delphi, string
is AnsiString
, an array of 8 bit character elements. Precisely what is needed to hold a UTF-8 payload.
In post-unicode Delphi, UTF8String
is still an AnsiString
, but this time with code page information.
type
UTF8String = type AnsiString(65001);
So, in all cases, you use UTF8String
to hold a UTF-8 encoded string.