Create Function
Return to Introduction  Previous page  Next page
The code output by the Create Function option is derived from a template file, CreateDBF.TPL, in the VOPP3 template directory. You can change the name of the template used through VOPP Plus!.

The following replacement markers are available in the template:

Replacement Marker
Description
%Fields%
FIELD statement containing each field in the DBF
%Structure%
array representing the DBF, formatted as DBStruct()
%BaseName%
the DBF name, without path or file extenstion
%Driver%
value of the Driver control on the dialog
%EraseProductionIndex%
code to delete a production index for the DBF
%CreateOrder%
DBCreateOrder() calls for each order
%RDDInherit%
some of the database drivers that can be selected involve an "inherited" RDD (e.g. DBFMEMO, DBFBLOB). You can reference the inherited RDD in the Creation template by using the %RDDInherit% marker - it will be substituted with an array version of the RDD name. As an example, if the selected driver was _DBFCDX/DBFMEMO then the %Driver% marker would be replace with _DBFCDX (no qoutes) and %RDDInherit% would be replace with {"DBFMEMO"}


An example function generated using the supplied template is shown below:

FUNCTION CreateCUSTOMER()
   LOCAL aStruct AS ARRAY
   LOCAL lAutoOpen AS USUAL
   LOCAL cBaseName AS STRING
   LOCAL lSuccess AS LOGIC

   FIELD CUSTNUM, FIRSTNAME, LASTNAME, ADDRESS, CITY, STATE, ZIP, PHONE
   FIELD FAX

   // Prevent any production index being opened automatically
   // this will let us delete it
   lAutoOpen := RDDINFO(_SET_AUTOOPEN,FALSE)
   
   aStruct := { ;
      { "CUSTNUM",    "N",    5,    0 }, ;
      { "FIRSTNAME",  "C",   10,    0 }, ;
      { "LASTNAME",   "C",   10,    0 }, ;
      { "ADDRESS",    "C",   25,    0 }, ;
      { "CITY",       "C",   15,    0 }, ;
      { "STATE",      "C",    2,    0 }, ;
      { "ZIP",        "C",    5,    0 }, ;
      { "PHONE",      "C",   13,    0 }, ;
      { "FAX",        "C",   13,    0 } ;
      }

   cBaseName := "CUSTOMER"

   IF ( lSuccess := DBCREATE(cBaseName,aStruct,"DBFNTX",,,,,) )

      IF ( lSuccess := DBUSEAREA(.T.,"DBFNTX",cBaseName,__UniqueAlias(cBaseName),FALSE,,,) )

         
         lSuccess := iif(lSuccess,DBSetOrderCondition(,,,,,,,,,,.F.),lSuccess)
         lSuccess := iif(lSuccess,DBCREATEORDER("CUSTNAME", "CUSTNAME.NTX", ;
            [lastname + firstname], {|| lastname + firstname }, .F.),lSuccess)

         lSuccess := iif(lSuccess,DBSetOrderCondition(,,,,,,,,,,.F.),lSuccess)
         lSuccess := iif(lSuccess,DBCREATEORDER("CUSTNUM", "CUSTNUM.NTX", ;
            [custnum], {|| custnum }, .F.),lSuccess)
         DBCLOSEAREA()

      ENDIF

   ENDIF

   RDDINFO(_SET_AUTOOPEN,lAutoOpen)

   RETURN lSuccess



© Piko Computing Consultants, 1998-2002