Unit 'Objects' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#rtl]

TDosStream.Truncate

Truncate the file on the current position.

Declaration

Source position: objects.pp line 365

procedure TDosStream.Truncate; virtual;

Description

If the status of the stream is stOK, then Truncate tries to truncate the stream size to the current file position.

Errors

If an error occurs, the stream's status is set to stError and ErrorInfo is set to the OS error code.

See also

TStream.Truncate

  

Truncate the stream size on current position.

TStream.GetSize

  

Return the size of the stream.

Example

Program ex16;

{ Program to demonstrate the TStream.Truncate method }

Uses Objects;

Var L : String;
    P : PString;
    S : PDosStream; { Only one with Truncate implemented. }

begin
  L:='Some constant string';
  { Buffer size of 100 }
  S:=New(PDosStream,Init('test.dat',stcreate));
  Writeln ('Writing "',L,'" to stream with handle ',S^.Handle);
  S^.WriteStr(@L);
  S^.WriteStr(@L);
  { Close calls flush first }
  S^.Close;
  S^.Open (stOpen);
  Writeln ('Size of stream is : ',S^.GetSize);
  P:=S^.ReadStr;
  L:=P^;
  DisposeStr(P);
  Writeln ('Read "',L,'" from stream with handle ',S^.Handle);
  S^.Truncate;
  Writeln ('Truncated stream. Size is : ',S^.GetSize);
  S^.Close;
  Dispose (S,Done);
end.

Documentation generated on: Nov 23 2024