Attempts to lock the current or specified table.
FLOCK([nWorkArea | cTableAlias])
- Specifies the work area of the table that FLOCK(В ) attempts to lock. Omitting nWorkArea or cTableAlias causes FLOCK(В ) to attempt locking the table that is open in the currently selected work area.
Specifies the alias of the table that FLOCK(В ) attempts to lock.
Note: Visual FoxPro generates an error message if you specify a table alias that does not exist.
Logical. FLOCK(В ) returns True (.T.) if the table is successfully locked. Otherwise, it returns False (.F.) under the following conditions:
The table or a record in the table is already locked by another user.
A table is not open in the work area you specify.
|If FLOCK() fails to lock a table and returns False (.F.), FLOCK() does not generate an error. As a result, you cannot use FLOCK() to trigger an ON ERROR routine.|
When a table is locked, the table is available for both read and write access by the user who placed the lock. Other users on the network have read-only access to the table. For information on how to lock a table and prevent access to it by other users, see SET EXCLUSIVE Command and USE Command.
A table remains locked until it is unlocked by the user who placed the lock. The table can be unlocked by issuing UNLOCK, closing the table, or quitting Visual FoxPro. Tables can be closed with USE, CLEAR ALL, or CLOSE DATABASES.
By default, FLOCK(В ) attempts to lock a table once. Use SET REPROCESS to automatically retry a table lock when the first attempt fails. SET REPROCESS determines the number of lock attempts, or the length of time during which lock attempts are made when the initial lock attempt is unsuccessful. For more information, see SET REPROCESS Command.
You can establish relations between two or more tables with SET RELATION. Placing a file lock on a table that is related to one or more tables doesn't place a file lock on the related tables. You must explicitly place and remove locks on the related tables.
For additional information about record and file locking and sharing tables on a network, see Programming for Shared Access.
CLOSE DATABASES OPEN DATABASE (HOME(2) + 'Data\testdata') USE products && Opens products table SET REPROCESS TO 3 SECONDS SELECT * FROM products INTO TABLE newprods IF FLOCK( ) *** New product initialization *** REPLACE ALL in_stock WITH 0.00 REPLACE ALL on_order WITH 0.00 WAIT 'Initialization Complete' WINDOW NOWAIT ELSE *** File is locked, warn user *** WAIT WINDOW 'Unable to open products file; try again later!' NOWAIT ENDIF BROWSE FIELDS in_stock, on_order && Displays newprods table USE ERASE newprods.dbf