_DBWrite( ) API Library Routine Example

The following example carries out a _DBReplace( ) using the two calling parameters, one a table field passed by reference, the other a value of the appropriate type. It executes a LIST NEXT 1 Visual FoxPro command before and after a call to _DBWrite( ).

Visual FoxPro Code

SET LIBRARY TO DBWRITE 
DO CreateTest
GO 3
=DBWRITE( @ABC, "Replacement Record 1")

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)
{
   int RetValue;

   if (RetValue = _DBReplace(&parm->p[0].loc, &parm->p[1].val)) {
      _UserError("\n_DBReplace() failed");
   }

   if (RetValue = _DBWrite(-1)) {
      _Error(-RetValue);
   }
   _Execute("LIST NEXT 1");
}

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