ID: Q117594
The information in this article applies to:
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.
To run the sample code below, you will need to use the following syntax:
USE <FoxPro_directory>\TUTORIAL\CUSTOMER
=DBLOCK1(@<fieldname>,"<info_to_replace>",<work_area_number>)
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'");*/
#include <pro_ext.h>
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
Last Reviewed: June 27, 1995