There is a Delphi 2007 Application that offers a WebService over RemObjects. I want now to pass a UTF-8 String to this application using this WebService. Now there are two String types that I could use in Delphi2007: Utf8String and WideString. (Utf8String is in Delphi 2007 equal to String - AnsiString)
I have tried it with both but only with the Utf8String it works. Is using a Utf8String correct or am I missing something else?
Asked
Active
Viewed 639 times
2

David Heffernan
- 601,492
- 42
- 1,072
- 1,490

frugi
- 605
- 7
- 26
1 Answers
3
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.

David Heffernan
- 601,492
- 42
- 1,072
- 1,490