Condividi tramite


_DBReplace( ) API Library Routine

_DBReplace( ) places a new value in a field.

int _DBReplace(Locator FAR *fld, Value FAR *val)
Locator FAR *fld;            /* Field to be replaced. */
Value FAR *val;            /* Value to be placed in field. */

Remarks

_DBReplace( ) returns 0 if the replacement is successful. If the replacement fails, _DBReplace( ) returns a negative integer whose absolute value is a Visual FoxPro error number. _DBReplace( ) can be used on a memo field to replace its value with a new value that's shorter than 65,000 bytes. To perform operations on memo fields that are larger than 65,000 bytes, you must use direct memo field routines and buffered file input/output routines.

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 functionality similar to the Visual FoxPro REPLACE command, but replaces the value of only one record at a time.

Visual FoxPro Code

SET LIBRARY TO DBREPLAC
DO CreateTest
? DBREPLACE(@ABC, "Replacement record 1")
? DBREPLACE(@ABC, 2)  && returns -302 - field ABC is character field

PROCEDURE CreateTest
   CREATE TABLE test (ABC C(20))
   APPEND BLANK
   REPLACE ABC WITH "This is record 1"
   APPEND BLANK
   REPLACE ABC WITH "This is record 2"
   APPEND BLANK
   REPLACE ABC WITH "This is record 3"
   APPEND BLANK
   REPLACE ABC WITH "This is record 4"
   GO TOP
RETURN

C Code

#include <pro_ext.h>

FAR Example(ParamBlk FAR *parm)
{
   _RetInt(_DBReplace(&parm->p[0].loc, &parm->p[1].val), 10);
}

FoxInfo myFoxInfo[] = {
   {"DBREPLACE", (FPFI) Example, 2, "R,?"},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

See Also

_DBLock( ) API Library Routine | _DBUnlock( ) API Library Routine | REPLACE Command | Accessing the Visual FoxPro API