_DBLock( ) API Library Routine

Attempts to lock the current record or the table open in the work area specified by workarea.

int _DBLock(int workarea, int RecOrFile)
int workarea;               /* Work area. */
int RecOrFile;               /* What is to be locked. */

Remarks

The RecOrFile parameter can be DBL_RECORD, to specify the current record, or DBL_FILE, to specify the table file. _DBLock( ) returns True (an integer other than 0) if the lock is successful, or False (0) if the lock isn't successful.

For more information on how to create an API library and integrate it with Visual FoxPro, see Accessing the Visual FoxPro API.

Example

The following example provides two API functions you can call from Visual FoxPro: XRLOCK( ), which locks the current record of the current work area; and XFLOCK( ), which locks the table open in the current work area. XRLOCK( ) calls _DBLock( – 1, DBL_RECORD( )), and XFLOCK( ) calls _DBLock( – 1, DBL_FILE( )).

Visual FoxPro Code

SET LIBRARY TO DBLOCK  
DO CreateTest
USE Test SHARED
GO 2
= XRLOCK()
LIST STAT  && shows that record #2 is locked
= XFLOCK()
LIST STAT  && shows that whole DBF is locked

PROCEDURE CreateTest

CREATE TABLE test (ABC C(20))
APPEND BLANK
REPLACE ABC WITH "Golly month of"
APPEND BLANK
REPLACE ABC WITH "A twelfth of"
APPEND BLANK
REPLACE ABC WITH "Hello, world"
APPEND BLANK
REPLACE ABC WITH "When in the"
GO TOP

RETURN

C Code

#include <pro_ext.h>

FAR xLockRecord(ParamBlk FAR *parm)
{
   _DBLock(-1, DBL_RECORD);
}

FAR xLockFile(ParamBlk FAR *parm)
{
   _DBLock(-1, DBL_FILE);
}

FoxInfo myFoxInfo[] =
{
   {"XRLOCK", (FPFI) xLockRecord, 0, ""},
   {"XFLOCK", (FPFI) xLockFile, 0, ""},
};

FoxTable _FoxTable =
{
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

See Also

_DBAppend( ) API Library Routine | _DBUnlock( ) API Library Routine | Accessing the Visual FoxPro API | Passing of Parameters to Visual FoxPro API Functions