home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
NETWERK
/
NETWERK.UNT
Wrap
Text File
|
1990-02-01
|
3KB
|
91 lines
Unit Network;
INTERFACE
function UnLock(var f;RecNr:integer):integer;
function Lock(var f;RecNr,Retries,DelayTime:integer):integer;
IMPLEMENTATION
uses Dos,Crt;
function HiLongint(l:longint):word;
var l0 : record { we use an absolute statement to }
Llow,Lhigh : word; { get the two separate words. This }
end absolute l; { is fast and dirty ! }
begin
HiLongint:=l0.Lhigh; { Assign the hi-two bytes }
end;
function LoLongint(l:longint):word;
var l0 : record { we use an absolute statement to }
Llow,Lhigh:word; { get the two separate words. This }
end absolute l; { is fast and and dirty ! }
begin
LoLongint:=l0.Llow; { Assign the lo-two bytes }
end;
function recordLockUnlock (var f;
RecNr,Retries,DelayTime: integer;
LockUnlock:byte):integer;
var
Fil : Filerec absolute f; { record size this file uses }
Regs : Registers; { needed for dos calls }
Offset : longint; { offset into file }
t : Integer; { for loop needs }
e : Integer; { the possible error code }
begin
e:=0; { start with error code=0 }
if retries<1 then retries:=1; { try at least 1 time ! }
while Retries>0 do { the number of retries }
begin
with Regs do
begin
AH:=$5C; { lock/unlock part of file }
AL:=LockUnlock; { 0=lock area, 1=unlock area}
BX:=Fil.Handle; { the file handle of file }
Offset:=RecNr*Fil.Recsize;{ determine record length }
{ and calculate first byte }
CX:=HiLongint(Offset); { store hi bytes of first }
DX:=LoLongint(Offset); { store lo bytes of first }
SI:=Hi(Fil.Recsize); { store hi byte of number }
DI:=Lo(Fil.Recsize); { store lo byte of number }
msdos(Regs); { (un)lock the record }
{ if there was an error then return error code in AX }
if (Flags and 1) <> 0 then { see if the locking was ok}
begin
AH:=$59; { get ext. errorcode dos }
BX:=0; { needed for call }
msdos(regs); { make the call }
e:=ax; { return with error code }
dec(Retries);
end
else
begin
e:=0; { there is no error }
Retries:=0; { no more retries, it is ok}
end;
end;
if Retries>0 then delay(DelayTime); { do we have to wait}
end;
RecordLockUnlock:=e; { return the error code, if any }
end;
function UnLock(var f; RecNr:integer):integer;
begin
{ Unlock needs no delay, and no retries ! }
Unlock:=RecordLockUnlock(f,RecNr,1,0,1); { 1 = unlock }
end;
function Lock(var f; RecNr,Retries,DelayTime:integer):integer;
begin
Lock:=RecordLockUnlock(f,RecNr,Retries,DelayTime,0);
{ 0 = lock }
end;
begin
{ No init needed }
end.