Skip to content

TMemoryStream.Truncate

Set the stream size to the current position.

Declaration

Source position: objects.pp line 408

default 
  procedure Truncate;  Virtual;

Description

Truncate sets the size of the memory stream equal to the current position. It de-allocates any memory-blocks that are no longer needed, so that the new size of the stream is the current position in the stream, rounded up to the first multiple of the stream blocksize.

Errors

If an error occurs during memory de-allocation, the stream's status is set to stError

See also

Name Description
TStream.Truncate Truncate the stream size on current position.

Example

Program ex20;
{ Program to demonstrate the TMemoryStream.Truncate method }
Uses Objects;
Var L : String;
    P : PString;
    S : PMemoryStream;
    I : Longint;
begin
  L:='Some constant string';
  { Buffer size of 100 }
  S:=New(PMemoryStream,Init(1000,100));
  Writeln ('Writing 100 times "',L,'" to stream.');
  For I:=1 to 100 do
    S^.WriteStr(@L);
  Writeln ('Finished.');
  S^.Seek(100);
  S^.Truncate;
  Writeln ('Truncated at byte 100.');
  Dispose (S,Done);
  Writeln ('Finished.');
end.