Technical Notes Database
TN976D.txt FILE MODE LOCKING/UNLOCKING ON A NETWORK
Category :Pascal
Platform :All
Product :Turbo Pascal 4.0+
Description:
Q. How can I access my data on a network when I have more than one user?
A. The routine in the following unit will help.
Using the fm* constants you can set the FILEMODE byte to match
the amount of sharing that you wish to take place.
example: FileMode := fmReadWr+fmDenyNone;
Using the Lock function you can lock a record or a series of records.
Lock returns True if the request to lock the record was successful. If
Lock returns False it can be assumed that the record was locked by someone
else and not available for editing at this time.
Locking Needs to take place anytime that a user will be allowed to change
the data. If your program in in a view mode you can safely leave the
record unlocked.
Unit NETio;
Interface
Const {File Open Mode Constants}
{ I SSS R AAA I= Inheritance Flag }
fmRead = $00;{ _ ___ 0 000 S= Sharing Mode Field }
fmWrite = $01;{ _ ___ 0 001 R= Reserved (must Be 0) }
fmReadWr = $02;{ _ ___ 0 010 A= Access Field }
fmCompat = $00 { _ 000 0 ___ }
fmDenyReadWr = $10 { _ 001 0 ___ }
fmDenyWrite = $20 { _ 010 0 ___ }
fmDenyRead = $30 { _ 011 0 ___ }
fmDenyNone = $40 { _ 100 0 ___ }
fmNotInher = $80 { 1 ___ 0 ___ }
Const
Lock = 0;
UnLock = 1;
Function Lock( Var FilVar; RecordNumber: longint;
Function LockRegion( Var FilVar; RecordNumber,NumRec: longint;
Lock_Unlock:byte ) : Word;
Implementation
Function LockRegion( Var FilVar; RecordNumber,NumRec: longint;
Lock_Unlock:byte ) : Word;
Var
R : registers;
ByteOffset : Longint;
begin
With FileRec(FilVar) do
Begin
ByteOffset := Recordnumber * RecSize;
NumRec := NumRec * RecSize;
With R do
Begin
AH := $5C;
AL := Lock_Unlock;
BX := Handle;
CX := (ByteOffset and $FFFF0000) shr 16;
DX := (ByteOffset and $0000FFFF);
SI := (NumRec and $FFFF0000) shr 16;
DI := (NumRec and $0000FFFF);
End;
Intr( $21, R );
if (R.Flags and 1) = 1 then
LockRegion := R.AX
Else
LockRegion := 0;
End;
end;
Function Locklock( Var FilVar; RecordNumber: longint;
Lock_Unlock:byte ) : Word;
Begin
Lock := LockRegion( FilVar, RecordNumber, 1, Lock_Unlock );
End;
ENd.
Reference:
7/16/98 4:35:38 PM
Last Modified: 01-SEP-99