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