opensubscriber
   Find in this group all groups
 
Unknown more information…

d : delphi@listserver.123.net.nz 30 June 2012 • 5:54PM -0400

[DUG] Potential bug in XE2
by Todd Martin

REPLY TO AUTHOR
 
REPLY TO GROUP




TStrings.SaveToStream calls Stream.WriteBuffer()
whereas
TStrings.LoadFromStream calls Stream.Read()

No buffering and no error message, if the buffer is not read in completely!

procedure TStrings.SaveToStream(Stream: TStream; Encoding: TEncoding);
var
  Buffer, Preamble: TBytes;
begin
  if Encoding = nil then
    Encoding := FDefaultEncoding;
  Buffer := Encoding.GetBytes(GetTextStr);
  if FWriteBOM then
  begin
    Preamble := Encoding.GetPreamble;
    if Length(Preamble) > 0 then
      Stream.WriteBuffer(Preamble[0], Length(Preamble));
  end;
  Stream.WriteBuffer(Buffer[0], Length(Buffer));
end;


procedure TStrings.LoadFromStream(Stream: TStream; Encoding: TEncoding);
var
  Size, PreambleSize: Integer;
  Buffer: TBytes;
begin
  BeginUpdate;
  try
    Size := Stream.Size - Stream.Position;
    SetLength(Buffer, Size);
    Stream.Read(Buffer[0], Size);
    PreambleSize:= TEncoding.GetBufferEncoding(Buffer, Encoding,
FDefaultEncoding);
    SetEncoding(Encoding); // Keep Encoding in case the stream is saved
    SetTextStr(Encoding.GetString(Buffer, PreambleSize, Length(Buffer) -
PreambleSize));
  finally
    EndUpdate;
  end;
end;


_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi@list...
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request@list... with Subject: unsubscribe

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.