home *** CD-ROM | disk | FTP | other *** search
- Program LockIt;
-
- Uses
- CRT,
- DOS,
- FileLock;
-
- Var
- f : File of Integer;
- i : integer;
- oldExit : Pointer;
-
- {$F+}
- Procedure MyExit;
- {$F-}
- Begin
- {$I-}
- ExitProc := oldExit;
- Seek ( f, 0 );
- While not EOF ( f ) Do
- Begin
- if Unlock ( f, FilePos ( f ), 1 ) Then ;
- Read ( f, i );
- End;
- Close ( f );
- i := IOResult;
- {$I+}
- End;
-
- Begin
- oldExit := ExitProc;
- ExitProc := @MyExit;
-
- Assign ( f, 'f:\data.dat' );
- Rewrite ( f );
- For i := 1 to 10 do
- Write ( f, i );
- Close ( f );
- FileMode := 66;
- Reset ( f );
- Repeat
- For i := 1 to 10 do
- Begin
- Repeat Until Lock ( f, i, 1 );
- Write ( 'Lock: ',i );
- Delay ( 4000 );
-
- Repeat Until Unlock ( f, i, 1 );
- WriteLn ( ' Unlocked' );
- Delay ( 4000 );
- End;
- Until KeyPressed;
- End.