Set the stream size to the current position.
Source position: objects.pp line 422
procedure TMemoryStream.Truncate; virtual; |
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.
If an error occurs during memory de-allocation, the stream's status is set to stError
|
Truncate the stream size on current position. |
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.