Click or drag to resize

Flock Function (Usual)

X#
Lock an opened and shared database file.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION Flock(
	uArea AS USUAL
) AS LOGIC
Request Example View Source

Parameters

uArea
Type: Usual
Specifies the work area name or number for a table on which the operation must be performed.

Return Value

Type: Logic
TRUE if the lock succeeded; otherwise, FALSE.
Remarks
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.
Examples
This example uses FLock() for a batch update of prices in INVENTORY.DBF:
X#
1USE inventory SHARED NEW
2IF Inventory->FLock()
3    REPLACE ALL Inventory->Price WITH ;
4            Inventory->Price * 1.1
5ELSE
6    QOut("File not available")
7ENDIF
This example attempts a file lock in an unselected work area:
X#
1USE sales NEW
2USE customer NEW
3IF !Sales->FLock()
4    QOut("Sales is in use")
5ENDIF
See Also