home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / t_power / locktest.pas < prev    next >
Pascal/Delphi Source File  |  1987-11-16  |  2KB  |  45 lines

  1. { LockTest - Lock4 test program by Richard Sadowsky }
  2. {$I-} { <<<====== Very Important! }
  3. program LockTest;
  4.  
  5. uses Lock4; { Use file locking routines }
  6.  
  7. var
  8.   UnTypedFile  : File;
  9.   TextFile : Text;
  10.   Error : Word;
  11.   S : String;
  12.   FPos,Flen : LongInt;
  13.  
  14. begin
  15.   FPos := 0;
  16.   FLen := 30000;               { arbitrarily large number }
  17.   WriteLn('DOS version ',DOS_Major,'.',DOS_Minor);
  18.   Assign(UnTypedFile,'Lock4.Pas');       { Open Lock4.pas as untyped file }
  19.   Reset(UnTypedFile,1);
  20.   if IOResult <> 0 then begin
  21.     WriteLn('Can not open LOCK4.PAS');
  22.     Halt
  23.   end;
  24.   Error := LockFile(GetHandle(UnTypedFile),FPos,FLen);
  25.                                                 { Lock the entire file }
  26.   WriteLn('Record locked, ErrorCode = ',Error); {show error code }
  27.   assign(TextFile,'Lock4.Pas'); { now, let's open the file again, this time }
  28.   Reset(TextFile);              { as a text file }
  29.   ReadLn(TextFile,S);           { Try to read it }
  30.   Error := IOResult;
  31.   WriteLn('Attemp to read while locked, ErrorCode = ',Error); { show Error }
  32.   Error := RetryFile(GetHandle(UnTypedFile),2,10);
  33.   WriteLn('Retries set to 10, ErrorCode = ',Error);
  34.   ReadLn(TextFile,S);           { Try to read it again}
  35.   Error := IOResult;
  36.   WriteLn('Attemp to read while locked, ErrorCode = ',Error); { show Error }
  37.   Error := UnLockFile(GetHandle(UnTypedFile),FPos,FLen); { now unlock it }
  38.   WriteLn('Record unlocked, ErrorCode = ',Error);
  39.   ReadLn(TextFile,S);           { and try again }
  40.   Error := IOResult;      { bet it worked!}
  41.   WriteLn('Attemp to read after Unlock, ErrorCode = ',Error);
  42.   Close(TextFile); {Close em up}
  43.   Close(UnTypedFile);
  44. end.
  45.