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 - dynindexinit() initializes a dynamic index alias http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 dynindexinit()      Initializes a dynamic index alias
------------------------------------------------------------------------------
 Declaration
   database.hdr

 Syntax
   proc dynindexinit extern
   param const char          cFileName, ;
         value ptr(_IDXFUNC) pFuncIndex, ;
               untyped       pBuffer, ;
         value uint          nBufferSize, ;
         value uint          nBufferType

 Arguments
   cFileName is the name of the index file.
   pFuncIndex is a pointer to the index expression function.
   pBuffer is the index buffer.
   nBufferSize is the size in bytes of the index buffer.
   nBufferType is the data type of the index buffer.

 Return
   None.

 Description
   The dynindexinit() function initializes the system-wide dynamic
   index alias structure (__dynindex) for indexing a dynamically opened
   database. The dynindexinit() function does not create or open the index
   file (use the index, reindex, and set index to commands for that purpose).

   The index expression function pointed to by the pFuncIndex parameter
   corresponds to the index expression in a conventional indexdef block.
   During indexing the index function is called back from the Force
   runtime system once for each record. The index expression function
   must use the dynrep() function for accessing fields in the
   dynamic database. The index function is responsible for placing
   appropriate values for each record to the index buffer.

   The index buffer specified by the pBuffer parameter corresponds to the
   index variable in an indexdef block. It must be a public or static
   variable placed in the data segment for its accessibility by the index
   function. The data type of the buffer variable depends on the type of
   the field(s) used by the index function for creating the index values.
   The nBufferType parameter must correctly inform the dynindexinit()
   function about the data type used.

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

   #define LEN_INDEXFIELD 15
   
   vardef static
      _PALIAS pDbf                          // dynamic alias pointer
      _FLDBAG sData
   enddef
   
   proc IdxFunc static                      // index expression function
   sData.pSet := 0
   dynrep( pDbf, 2, sData )
   endproc
   
   proc Test_dynindexinit
   vardef
      char cFirst, cLast
   enddef
   pDbf := dynopen( 0, "stest.dbf", DO_SHARED ) // open database
   dynindexinit( "test.fdx", &IdxFunc, sData.cChar, LEN_INDEXFIELD, FT_CHAR )
   index __dynindex                         // create index
   seek "Vanderbilt"                        // seek for a name
   if found()
      sData.pSet := 0
      dynrep( pDbf, 1, sData )
      cFirst := sData.cChar
      sData.pSet := 0
      dynrep( pDbf, 2, sData )
      cLast := sData.cChar
      ? "Record found", istr( recno() ), trim( cFirst ), cLast
   endif
   endproc

   proc main
   Test_dynindexinit()
   endproc

See Also: __dynindex dynopen()

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