Locks a data file and restricts the access to this data file for all other sites or applications. Then, the data file can be unlocked by HUnlockFile
Several cases may occur after the call to HLockFile:
- A file record is already locked by another application: the lock cannot be performed.
- The data file is already locked by another application: the lock cannot be performed.
// Lock the CUSTOMER data file
IF HLockFile(CUSTOMER, hLockReadWrite) = False THEN
IF HErrorLock() = True THEN
Error("Operation not allowed")
// Process on data file ...
// Restore access to data file
<Result> = HLockFile([<Data file> [, <Lock>]])
- True if the lock was performed,
- False if a problem occurred (the file is already locked for example). HError is used to identify the error.
<Data file>: Optional character string
Name of the data file used.
If this name is not specified, HLockFile will use the last data file used by the last HFSQL function (function starting with "H").
<Lock>: Optional integer constant
Used to define the type of lock performed on the data file:
|hLockReadWrite||Lock in read/write: the records found in the data file cannot be read or modified by another application. No lock on the data file can be defined by another application.|
|Lock in write mode: the records found in the data file can be read by another application but cannot be modified by another application. No lock on the data file can be defined by another application.|
<Lock> is ignored.
Modifying the type of lock for a data file
To modify the type of lock applied to a data file, call HLockFile and specify the requested type of lock. There is no need to unlock the data file beforehand.
Effect of lock mode
If the data file lock mode is set to hModeMono
has no effect.
If the data file (or one of its records) is already locked, the lock request is retried H.NbRetry
times (50 by default).
If the data file cannot be locked after H.NbRetry