delphidelphi-2007remobjects

When passing a UTF8 String to RemObject (Delphi 2007) which String Type to use - Utf8String or WideString


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) RemObjects - UTF8String vs WideString I have tried it with both but only with the Utf8String it works. Is using a Utf8String correct or am I missing something else?


Solution

  • 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.