Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- CA-Clipper 5.3 . Guide To CA-Clipper - <b>indexkey()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 INDEXKEY()
 Return the key expression of a specified index
------------------------------------------------------------------------------
 Syntax

     INDEXKEY(<nOrder>) --> cKeyExp

 Arguments

     <nOrder> is the ordinal position of the index in the list of index
     files opened by the last USE...INDEX or SET INDEX TO command for the
     current work area.  A zero value specifies the controlling index,
     without regard to its actual position in the list.

 Returns

     INDEXKEY() returns the key expression of the specified index as a
     character string.  If there is no corresponding index or if no database
     file is open, INDEXKEY() returns a null string ("").

 Description

     INDEXKEY() is a database function that determines the key expression of
     a specified index in the current work area and returns it as a character
     string.  To evaluate the key expression, specify INDEXKEY() as a macro
     expression like this: &(INDEXKEY(<nOrder>)).

     INDEXKEY() has a number of applications, but two specific instances are
     important.  Using INDEXKEY(), you can TOTAL on the key expression of the
     controlling index without having to specify the key expression in the
     source code.  The other instance occurs within a DBEDIT() user function.
     Here, you may want to determine whether or not to update the screen
     after the user has edited a record.  Generally, it is only necessary to
     update the screen if the key expression of the controlling index has
     changed for the current record.  Both of these examples are illustrated
     below.

     By default, INDEXKEY() operates on the currently selected work area.  It
     can be made to operate on an unselected work area by specifying it
     within an aliased expression (see example below).

 Examples

     .  This example accesses the key expression of open indexes in
        the current work area:

        #define ORD_NATURAL      0
        #define ORD_NAME         1
        #define ORD_SERIAL      2
        //
        USE Customer INDEX Name, Serial NEW
        SET ORDER TO ORD_SERIAL
        ? INDEXKEY(ORD_NAME)         // Result: Name index exp
        ? INDEXKEY(ORD_SERIAL)      // Result: Serial index exp
        ? INDEXKEY(ORD_NATURAL)      // Result: Serial index exp

     .  This example accesses the key expression of the controlling
        index in an unselected work area:

        USE Customer INDEX Name, Serial NEW
        USE Sales INDEX Salesman NEW
        ? INDEXKEY(0), Customer->(INDEXKEY(0))

     .  This example uses INDEXKEY() as part of a TOTAL ON key
        expression.  Notice that INDEXKEY() is specified using a macro
        expression to force evaluation of the expression:

        USE Sales INDEX Salesman NEW
        TOTAL ON &(INDEXKEY(0)) FIELDS SaleAmount TO ;
              SalesSummary

     .  This example uses INDEXKEY() to determine whether the DBEDIT()
        screen should be updated after the user has edited the current field
        value.  Generally, you must update the DBEDIT() screen if the user
        changes a field that is part of the controlling index key.
        FieldEdit() is a user-defined function called from a DBEDIT() user
        function to edit the current field if the user has pressed an edit
        key.

        #include "Dbedit.ch"
        #define ORD_NATURAL   0
        FUNCTION FieldEdit()
           LOCAL indexVal
           // Save current key expression and value
           indexVal = &(INDEXKEY(ORD_NATURAL))
           .
           . <code to GET current field value>
           .
           // Refresh screen if key value has changed
           IF indexVal != &(INDEXKEY(ORD_NATURAL))
              nRequest = DE_REFRESH
           ELSE
              nRequest = DE_CONT
           ENDIF
           RETURN nRequest

 Files   Library is CLIPPER.LIB.


See Also: INDEX INDEXEXT() INDEXORD() SET INDEX SET ORDER

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