_DBLock( ) API Library Routine 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
};