> {quote:title=Remy Lebeau (TeamB) wrote:}{quote} > <Dalija Prasnikar> wrote in message news:✉forums.embarcadero.com... > > > Actually, it would be the best if you skip using any kind of > > string stream and load string directly. > > There are three problems with that code: > > 1) you are using RawByteString, but you are not specifying any codepage for > it. > > 2) you need to use TStream.ReadBuffer() instead of TStream.Read() to ensure > the entire string is read. > > 3) if Size is -1, but the TStream does not have anything left to read, you > allocate a 0-length String (thus the String is nil) but then dereference it, > which will crash. > > Try this instead: > > {code:delphi} > function RawStringLoadFromStream(Stream: TStream; Size: Integer = -1): > RawByteString; > begin > if Size = -1 then Size := Stream.Size - Stream.Position; > if Size <= 0 then Result := '' > else > begin > SetLength(Result, Size); > Stream.ReadBuffer(Result[1], Size); > SetCodePage(Result, SomeCodePageHere, False); > end; > end; > {code} >
Thanks!
Dalija Prasnikar