Microsoft KB Archive/117594

{| = _DBReplace Function Requires Record to Be Locked =
 * width="100%"|

ID: Q117594

The information in this article applies to:


 * Microsoft FoxPro Library Construction Kit for MS-DOS, versions 2.0, 2.5, 2.6
 * Microsoft FoxPro Library Construction Kit for Windows, versions 2.5, 2.6

SUMMARY
When you are attempting to use the _DBReplace function to place a new value in a field, _DBReplace will return a negative integer if the current record is not locked.

_DBReplace provides functionality similar to the FoxPro REPLACE command, but replaces the value of only one record at a time. When you attempt to use _DBReplace to place a new value in a field, _DBReplace will return a 0 if the replacement was successful or a negative integer whose absolute value is a FoxPro error number if the replacement was unsuccessful. Unlike the FoxPro REPLACE command, _DBReplace must lock the current record in order to perform the replacement.

The sample code below illustrates how the _DBReplace function works.

MORE INFORMATION
To run the sample code below, you will need to use the following syntax:

USE \TUTORIAL\CUSTOMER =DBLOCK1(@ ,"",) When you are using _DBReplace, you must pass the name of the field that contains the information you want to replace. NOTE: To see the error, you must comment (remark) out the following line of code as shown (this line is used to lock the record):

/*if(_DBLock((int)parm->p[2].val.ev_long,DBL_RECORD) <= 0) _Execute("Wait Window 'Could not lock record'");*/

Sample Code
#include 

void FAR dbfunc(ParamBlk FAR *parm) {     int retval=0; _DBUnwind((int)parm->p[2].val.ev_long); _DBAppend((int)parm->p[2].val.ev_long,0);

if(_DBLock((int)parm->p[2].val.ev_long,DBL_RECORD) <= 0) _Execute("Wait Window 'Could not lock record'");

/*_Execute("=RLOCK") can also be used*/

retval=_DBReplace(&parm->p[0].loc,&parm->p[1].val);

if(retval<=-1) _Error(retval);

_DBUnlock((int)parm->p[2].val.ev_long); /*_Execute("UNLOCK") can also be used*/ }

FoxInfo myFoxInfo[] = {  {"DBLOCK1", (FPFI) dbfunc, 3, "R,C,I"} };

FoxTable _FoxTable = {  (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; Additional reference words: FoxWin FoxDos 2.00 2.50 2.60 API LCK KBCategory: kbinterop kbtool kbprg kbcode KBSubcategory: FxtoolLck
 * }