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 - indexdef index alias declaration block http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 indexdef            Index alias declaration block
------------------------------------------------------------------------------
 Syntax
   indexdef [<scope>]
      <datatype>[( <width> )] <indexalias> <indexexpression>
   enddef

 Arguments
   <scope> is the range of visibility for the declared index alias (public,
   static, extern).

   <datatype> is the data type of the index expression.

   <width> is the length of the index variable.

   <indexalias> is the symbol name of the index declaration.

   <indexexpression> is the expression that controls indexing.

 Description
   The indexdef keyword initiates an index declaration block.
   The index declaration block serves as a template for an index alias
   that can be used in conjunction with indexing commands.

 Example
   #define EXAMPLE_KEYWORD
   #include example.hdr

   /*
   An index expression function can contain any sort of code as
   long as the function returns an index generation value. In this
   example the index expression function is used to show the percent
   indexed records. Note that the on index do command can be used to
   display the progress of an indexing.
   */
   
   dbfdef sTest
      char( 20 ) firstname
      char( 20 ) lastname
   enddef
   
   vardef static
      ulong nRecs := 0
   enddef
   
   func char IndexExpr static
   // Show every 100 records while indexing
   nRecs++
   if nRecs % 100 == 0
      @ row(), 0 ?? str( 100 * arecno( sTest ) / areccount( sTest ), 3, 0 ) + ;
         + " percent finished"
   endif
   return( trim( sTest->firstname ) + " " + trim( sTest->lastname ) )
   endpro
   
   indexdef
      char( 41 ) sIdx IndexExpr()
   enddef
   
   proc Test_indexdef
   vardef
      ulong n
   enddef
   ? "Making database..."
   build "stest.dbf" from alias sTest
   open sTest
   for n := 1 to 10000
      append blank
      sTest->firstname := "Fred"
      sTest->lastname  := "Flintstone"
   next
   ? "Indexing..."
   ?
   index sIdx unique
   close all
   erase "stest.dbf"
   erase "sidx.fdx"
   endproc

   proc main
   Test_indexdef()
   endproc

See Also: dbfdef

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