home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST1205.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-11-21  |  859 b   |  54 lines

  1. Program LockIt;
  2.  
  3. Uses
  4.   CRT,
  5.   DOS,
  6.   FileLock;
  7.  
  8. Var
  9.   f       : File of Integer;
  10.   i       : integer;
  11.   oldExit : Pointer;
  12.  
  13. {$F+}
  14. Procedure MyExit;
  15. {$F-}
  16. Begin
  17. {$I-}
  18.   ExitProc := oldExit;
  19.   Seek ( f, 0 );
  20.   While not EOF ( f ) Do
  21.   Begin
  22.     if Unlock ( f, FilePos ( f ), 1 ) Then ;
  23.     Read ( f, i );
  24.   End;
  25.   Close ( f );
  26.   i := IOResult;
  27. {$I+}
  28. End;
  29.  
  30. Begin
  31.   oldExit := ExitProc;
  32.   ExitProc := @MyExit;
  33.  
  34.   Assign ( f, 'f:\data.dat' );
  35.   Rewrite ( f );
  36.   For i := 1 to 10 do
  37.     Write ( f, i );
  38.   Close ( f );
  39.   FileMode := 66;
  40.   Reset ( f );
  41.   Repeat
  42.     For i := 1 to 10 do
  43.     Begin
  44.       Repeat Until Lock ( f, i, 1 );
  45.       Write ( 'Lock: ',i );
  46.       Delay ( 4000 );
  47.  
  48.       Repeat Until Unlock ( f, i, 1 );
  49.       WriteLn ( '   Unlocked' );
  50.       Delay ( 4000 );
  51.     End;
  52.   Until KeyPressed;
  53. End.
  54.