_DBUnlock( ) API Library Routine Example

The following example uses _DBUnlock( ) to unlock all records of the table open in the current work area. The Visual FoxPro code demonstrates _DBUnlock( ) and verifies that it's working properly.

Visual FoxPro Code

SET LIBRARY TO DBUNLOCK
DO CreateTest
USE Test SHARED
GO 2
= XRLOCK()
LIST STAT  && shows that record #2 is locked
= XUNLOCK()
LIST STAT  && shows no records are locked
= XFLOCK()
LIST STAT  && shows that whole DBF is locked
= XUNLOCK()
LIST STAT  && shows no records are 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);
}
FAR xUnLockFile(ParamBlk FAR *parm)
{
   _DBUnLock(-1);
}
FoxInfo myFoxInfo[] = {
   {"XRLOCK",  (FPFI) xLockRecord, 0, ""},
   {"XFLOCK",  (FPFI) xLockFile, 0, ""},
   {"XUNLOCK", (FPFI) xUnLockFile, 0, ""},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};