Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide To Clipper - <b>declare</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
DECLARE


Syntax:     DECLARE <array1>[<expN1>] [,<array2>[<expN2>]]...

Purpose:    To create one or more memory variable arrays.

Arguments:  <array> is the name of an array to create.  Note that
            you can create more than one array with a single DECLARE
            statement.

            <expN> is the number of elements in the array up to a
            maximum of 4096.  An array DECLAREd with less than one
            element defaults to one; more than 4096 elements defaults to
            4096.

            Note: The square brackets surrounding <expN> are a
            required part of the command syntax and in this case do not
            signify an optional argument.

Usage:      DECLARE creates single dimensional private arrays.  At the
            same time, PUBLIC and private arrays created in higher-level
            procedures with the same name are hidden.  An array uses one
            memory variable slot of the allotted memory variables.

            Unlike memory variables, arrays and array elements cannot be
            saved in (.mem) files.

            To assign a value to an array element, use the assignment
            operator (=) or the STORE command.  To STORE a value to an
            entire array, use AFILL().  To retrieve a value from an
            array, refer to the element using a subscript indicating its
            position in the array.

            To determine the number of elements in an array, use LEN()
            by specifying only the array name as the function argument.

            Data types: Elements within the same array can be mixed
            type and obey all the typing rules of ordinary memory
            variables.  TYPE() returns an "A" for an array reference and
            the data type of an element if the reference includes the
            subscript.

            Use within macro variables: References to arrays and
            array elements can be made with macro variables with one
            exception:  the brackets cannot be in a macro variable when
            DECLAREing the array.  Note, however, that you cannot use or
            expand an array element as a macro variable.  If you wish to
            use an array element in a macro, assign the contents of the
            array element to a memory variable and then use the memory
            variable as the macro variable.  For example:

            DECLARE fields[FLDCOUNT()]
            AFIELDS(fields)
            fld_name = fields[1]
            ? &fld_name.

            Passing parameters: Array and array elements can be
            passed as parameters to Clipper procedures, user-defined
            functions, and external procedures that use the Extend
            System.  Arrays are passed by reference and array elements
            are passed by value.  You cannot, however, pass entire
            arrays to external procedures using the CALL command.  In
            this case, you can only pass array elements one at a time.

            PUBLIC arrays: To create PUBLIC arrays, use the PUBLIC
            statement.  PUBLIC arrays follow all the same rules as
            private arrays with the exception of the scope.  See PUBLIC
            for more information.

Library:    CLIPPER.LIB


----------------------------------- Examples -------------------------------

   The following example creates an array, assigns values to elements,
   and then displays them:

   DECLARE array[5]
   array[1] = "Hello"
   array[2] = 1234
   ? array[1]                 && Result: Hello
   ? array[2]                 && Result: 1234


   This example demonstrates how to refer to arrays with macro
   variables:

   name = "array"
   number = 5
   name_len = "array[1]"

   * Legal use.
   DECLARE &name.[number]     && Creates "array" with 5 elements.
   &name_len. = 100           && Assigns 100 to element 1.
   &name.[3]  = "abc"         && Assigns "abc" to element 3.

   * Illegal use.
   DECLARE &name_len.         && The brackets cannot be
                              && within the macro variable.


See Also: PRIVATE PUBLIC ADIR() AFILL() AINS()

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