I created the following code:
Function AnsiStringToStream(Const AString: AnsiString): TStream;
Begin
Result := TStringStream.Create(AString, TEncoding.ANSI);
End;
But I'm "W1057 Implicit string cast from 'AnsiString' to 'string'"
There is something wrong with him?
Thank you.
In D2009+,
TStringStream
expects aUnicodeString
, not anAnsiString
. If you just want to write the contents of theAnsiString
as-is without having to convert the data to Unicode and then back to Ansi, useTMemoryStream
instead:Since
AnsiString
is codepage-aware in D2009+, ANY string that is passed to your function will be forced to the OS default Ansi encoding. If you want to be able to pass any 8-bit string type, such asUTF8String
, without converting the data at all, useRawByteString
instead ofAnsiString
: