ex15.pp 740 B

12345678910111213141516171819202122232425262728293031
  1. Program ex15;
  2. { Program to demonstrate the TStream.Flush method }
  3. Uses Objects;
  4. Var L : String;
  5. P : PString;
  6. S : PBufStream; { Only one with Flush implemented. }
  7. begin
  8. L:='Some constant string';
  9. { Buffer size of 100 }
  10. S:=New(PBufStream,Init('test.dat',stcreate,100));
  11. Writeln ('Writing "',L,'" to stream with handle ',S^.Handle);
  12. S^.WriteStr(@L);
  13. { At this moment, there is no data on disk yet. }
  14. S^.Flush;
  15. { Now there is. }
  16. S^.WriteStr(@L);
  17. { Close calls flush first }
  18. S^.Close;
  19. Writeln ('Closed stream. File handle is ',S^.Handle);
  20. S^.Open (stOpenRead);
  21. P:=S^.ReadStr;
  22. L:=P^;
  23. DisposeStr(P);
  24. Writeln ('Read "',L,'" from stream with handle ',S^.Handle);
  25. S^.Close;
  26. Dispose (S,Done);
  27. end.