home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
NEWS
/
554
/
MAI
/
SHARLOCK.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-10-07
|
4KB
|
117 lines
{─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 435 of 505
From : Bob Swart 2:281/256.12 25 Apr 93 20:59
To : Bas van Gaalen 2:285/209.0
Subj : Multitasking/Share
────────────────────────────────────────────────────────────────────────────────
Hoi Bas!
> Currently I'm writing a program which must be able to handle
> multitask environments.
I have done the same, some time ago.
> I have a share-unit which takes care of the most. But as I'm trying to
> write a record which is open in another window (of DesqView for
> instance) then a runtime error 5 appears.
Use the unit below (probably together with your share unit) to LOCK and UNLOCK
the needed records of your file(s). If you notice a record is locked, just wait
until it is unlocked.}
{$IFDEF VER70}
{$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,P-,Q-,R-,S+,T-,V-,X-}
{$ELSE}
{$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,R-,S+,V-,X-}
{$ENDIF}
Unit SharLock;
{
SharLock 1.0
Borland Pascal (Objects) 7.0.
Copyright (c) 14-3-1993 DwarFools & Consultancy by drs. Robert E. Swart.
P.O. box 799
5702 NP Helmond
The Netherlands
Code size: 332 bytes
Data size: 0 bytes
------------------------------------------------------------------------
This unit provides file sharing and record locking facilities. Read the
article in the Magazine DOS Special 2/93 for more information about this
unit.
}
Interface
Const
fmReadOnly = $00;
fmWriteOnly = $01;
fmReadWrite = $02;
fmDenyAll = $10;
fmDenyWrite = $20;
fmDenyRead = $30;
fmDenyNone = $40;
fmNoInherit = $80;
function LockRegion(var F: File; BegByte,NrByte: LongInt): Word;
function UnLockRegion(var F: File; BegByte,NrByte: LongInt): Word;
function LockRecords(var F: File; RecNr,NrRec: LongInt): Word;
function UnLockRecords(var F: File; RecNr,NrRec: LongInt): Word;
Implementation
Uses Dos;
function FLock(Handle: Word; Pos,Len: LongInt): Word; Assembler;
ASM
mov AL,0 { subfunction 0: lock region }
mov AH,$5C { DOS function $5C: FLOCK }
mov BX,Handle { put FileHandle in BX }
les DX,Pos
mov CX,ES { CX:DX begin position }
les DI,Len
mov SI,ES { SI:DI length lockarea }
int $21
jb @End { if error then return AX }
xor AX,AX { else return 0 }
@End:
end {FLock};
function FUnLock(Handle: Word; Pos,Len: LongInt): Word; Assembler;
ASM
mov AL,1 { subfunct. 1: unlock region }
mov AH,$5C { DOS function $5C: FLOCK }
mov BX,Handle { put FileHandle in BX }
les DX,Pos
mov CX,ES { CX:DX begin position }
les DI,Len
mov SI,ES { SI:DI length lockarea }
int $21
jb @End { if error then return AX }
xor AX,AX { else return 0 }
@End:
end {FUnLock};
function LockRegion(var F: File; BegByte,NrByte: LongInt): Word;
begin
LockRegion := FLock(FileRec(F).Handle,BegByte,NrByte)
end {LockRegion};
function UnLockRegion(var F: File; BegByte,NrByte: LongInt): Word;
begin
UnLockRegion := FUnLock(FileRec(F).Handle,BegByte,NrByte)
end {UnLockRegion};
function LockRecords(var F: File; RecNr,NrRec: LongInt): Word;
begin
LockRecords := FLock(FileRec(F).Handle,
(RecNr * FileRec(F).RecSize)-1,
NrRec * FileRec(F).RecSize)
end {LockRecords};
function UnLockRecords(var F: File; RecNr,NrRec: LongInt): Word;
begin
UnLockRecords := FUnLock(FileRec(F).Handle,
(RecNr * FileRec(F).RecSize)-1,
NrRec * FileRec(F).RecSize)
end {UnLockRecords};
end.