ex37.pp 786 B

123456789101112131415161718192021222324252627282930313233343536
  1. Program Example37;
  2. { This program demonstrates the FileCreate function }
  3. Uses sysutils;
  4. Var I,J,F : Longint;
  5. Begin
  6. F:=FileCreate ('test.dat');
  7. If F=-1 then
  8. Halt(1);
  9. For I:=0 to 100 do
  10. FileWrite(F,I,SizeOf(i));
  11. FileClose(f);
  12. F:=FileOpen ('test.dat',fmOpenRead);
  13. For I:=0 to 100 do
  14. begin
  15. FileRead (F,J,SizeOF(J));
  16. If J<>I then
  17. Writeln ('Mismatch at file position ',I)
  18. end;
  19. FileSeek(F,0,fsFromBeginning);
  20. Randomize;
  21. Repeat
  22. FileSeek(F,Random(100)*4,fsFromBeginning);
  23. FileRead (F,J,SizeOf(J));
  24. Writeln ('Random read : ',j);
  25. Until J>80;
  26. FileClose(F);
  27. F:=FileOpen('test.dat',fmOpenWrite);
  28. I:=50*SizeOf(Longint);
  29. If FileTruncate(F,I) then
  30. Writeln('SuccessFully truncated file to ',I,' bytes.');
  31. FileClose(F);
  32. End.