ex16.pp 715 B

123456789101112131415161718192021222324252627282930
  1. Program ex16;
  2. { Program to demonstrate the TStream.Truncate method }
  3. Uses Objects;
  4. Var L : String;
  5. P : PString;
  6. S : PDosStream; { Only one with Truncate implemented. }
  7. begin
  8. L:='Some constant string';
  9. { Buffer size of 100 }
  10. S:=New(PDosStream,Init('test.dat',stcreate));
  11. Writeln ('Writing "',L,'" to stream with handle ',S^.Handle);
  12. S^.WriteStr(@L);
  13. S^.WriteStr(@L);
  14. { Close calls flush first }
  15. S^.Close;
  16. S^.Open (stOpen);
  17. Writeln ('Size of stream is : ',S^.GetSize);
  18. P:=S^.ReadStr;
  19. L:=P^;
  20. DisposeStr(P);
  21. Writeln ('Read "',L,'" from stream with handle ',S^.Handle);
  22. S^.Truncate;
  23. Writeln ('Truncated stream. Size is : ',S^.GetSize);
  24. S^.Close;
  25. Dispose (S,Done);
  26. end.