Functions.Flock Method (Usual)
Lock an opened and shared database file.
XSharp.RT (in XSharp.RT.dll) Version: 2.18
Syntax Request Example
uArea AS USUAL
) AS LOGIC
public static bool Flock(
- Type: Usual
Specifies the work area name or number for a table on which the operation must be performed.
TRUE if the lock succeeded; otherwise, FALSE.
If a database file is opened in shared mode, you must obtain a file lock before attempting any operation that updates the database file with a scope or a condition.
For each invocation of FLock(), there is one attempt to lock the database file (and other related files, such as index and memo files), and the result is returned as a logical value.
A file lock fails if another process currently has a file or record lock for the same database file.
If FLock() is successful, the file lock is locked and other processes are prevented from making updates until the lock is released. FLock() provides a shared lock, allowing other users read-only access to the locked file while allowing only the current process to modify it.
A file lock remains in effect until you close the database, explicitly unlock it (with DBUnLock(), for example), or attempt another file or record lock (with RLock() or DBRLock()).
By default, this function operates on the currently selected work area.
It can be made to operate on an unselected work area by specifying
it within an aliased expression or by calling the overload that accepts a workarea
parameter (a workarea number or alias ).
This feature is useful since FLock() does not automatically attempt a file lock for related files.
This example uses FLock() for a batch update of prices in INVENTORY.DBF:
1USE inventory SHARED NEW
3 REPLACE ALL Inventory->Price WITH ;
4 Inventory->Price * 1.1
6 QOut("File not available")
This example attempts a file lock in an unselected work area:
1USE sales NEW
2USE customer NEW
4 QOut("Sales is in use")