Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - dynrep() set or get the contents of a field http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 dynrep()            Set or get the contents of a field
------------------------------------------------------------------------------
 Declaration
   database.hdr

 Syntax
   func byte dynrep extern
   param value _PALIAS pAlias, ;
         value uint    uField, ;
               _FLDBAG sData


 Arguments
   pAlias is the alias for the database to access.

   uField is the ordinal number of the field.

   sData is a field data storage structure.

 Return
   The dynamic type of the field accessed.

 Description
   The dynrep() function sets or gets the contents of a database field.
   It is primarily used with dynamic aliases where the field names are not
   known at compile time.

   The function accesses the field given by the uField parameter of the
   database referred to by pAlias.  The direction of operation is
   dependent of the value of the sData.pSet member of the data storage
   parameter (see the typedef of sData in database.hdr).

   If sData.pSet is set to 0, then dynrep() fetches the contents of the
   field in that member of the sData structure whose data type corresponds
   to the type of the field in question. Upon return the sData.pSet member
   points to the filled member of the same structure. The return value
   of the function indicates the type of the field.

   When setting a field's value, the sData.pSet member must be non-zero,
   and the member of sData whose data type corresponds to the field type must
   contain the value that is to be placed in the field.

 Example
   #define EXAMPLE_DATABASE
   #define _DYNALIAS_
   #define _ALIASPTR_
   #include example.hdr

   proc Test_dynrep
   vardef
      _PALIAS pDbf
      _FLDBAG sData
   enddef
   pDbf := dynopen( 0, "stest.dbf", DO_SHARED ) // open database
   if pDbf                                      // if successful
   
      sData.pSet := 0            // indicate getting field contents
      dynrep( pDbf, 1, sData )   // get current contents of 1st field
      ? "Original: ", sData.cChar
   
      sData.pSet := 0            // indicate getting field contents
      dynrep( pDbf, 6, sData )   // get current contents of 6th field
      ?? sData.dDate
   
      sData.pSet := 1            // indicate setting field contents
      sData.cChar := "Replaced"  // place new value in structure member
      dynrep( pDbf, 1, sData )   // set 1st field
   
      sData.pSet := 1            // indicate setting field contents
      sData.dDate := today()     // place new value in structure member
      dynrep( pDbf, 6, sData )   // set 6th field
   
      sData.pSet := 0            // indicate getting field contents
      dynrep( pDbf, 1, sData )   // get changed contents of 1st field
      ? "Changed:  ", sData.cChar
   
      sData.pSet := 0            // indicate getting field contents
      dynrep( pDbf, 6, sData )   // get changed contents of 6th field
      ?? sData.dDate
   
      dynclose( pDbf )           // close database
   else
      ? "Database could not be opened"
   endif
   endproc

   proc main
   Test_dynrep()
   endproc

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson