I created the following code:
Function AnsiStringToStream(Const AString: AnsiString): TStream;
Begin
Result := TStringStream.Create(AString, TEncoding.ANSI);
End;
但I m “W1057 强行从AnsiString引向“扼杀”
他有什么错误?
谢谢。
I created the following code:
Function AnsiStringToStream(Const AString: AnsiString): TStream;
Begin
Result := TStringStream.Create(AString, TEncoding.ANSI);
End;
但I m “W1057 强行从AnsiString引向“扼杀”
他有什么错误?
谢谢。
在D2009+,TStringStream
预计UnicodeString/code>,而不是
的内容,就不必将数据转换为Unicode,然后回给Ansi,则使用<条码>TMemoryStream:AnsiString
。 如果你只想写<条码>AnsiString
function AnsiStringToStream(const AString: AnsiString): TStream;
begin
Result := TMemoryStream.Create;
Result.Write(PAnsiChar(AString)^, Length(AString));
Result.Position := 0;
end;
由于AnsiString
是D2009+的编码网页-aware,被传至您职务的ANY string将被迫服从于本组织违约的Ansi encoding。 如果您希望能通过任何8个轨道型号,例如UTF8String
,而不将数据作任何改动,则使用<代码>RawByteString而不是AnsiString
:
function AnsiStringToStream(const AString: RawByteString): TStream;
begin
Result := TMemoryStream.Create;
Result.Write(PAnsiChar(AString)^, Length(AString));
Result.Position := 0;
end;
The TStringStream
constructor expects a string as its parameter. When you give it an an AnsiString
instead, the compiler has to insert conversion code, and the fact that you ve specified the TEncoding.ANSI
doesn t change that.
Try it like this instead:
Function AnsiStringToStream(Const AString: AnsiString): TStream;
Begin
Result := TStringStream.Create(string(AString));
End;
这需要明确的转换,使汇编者了解如何照顾到与编码相关的工作。
my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...
Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...
i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...
In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...
What is the equivalent of SetLength using Oxygene? I m trying to size an integer array. var listIndexes: array of integer; begin setLength(listIndexes,5); // doesn t work end;
How can I monitor or visualize memory fragmentation of a delphi application?
I have consistently had IDE problems in Delphi/C++Builder for years, with every version. I usually just reboot, recompile, etc. and move on. However, I keep seeing others say that the IDE is rock ...
I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...