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 . Technical Reference - <b>_itemarrayget()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _itemArrayGet()
 Retrieve an element of an item of type array
------------------------------------------------------------------------------
 C Prototype

     #include "item.api"
     ITEM _itemArrayGet(
                         ITEM itmArr,
                         USHORT uiElem
                       )

 Arguments

     itmArr is the item of type array from which to retrieve an element.

     uiElem is the element number to retrieve.

 Returns

     A new item containing a reference to the element number requested from
     the array.

 Description

     You can use _itemArrayGet() to retrieve a particular element of an
     array.  The element retrieved may be any type supported by the Item API,
     and may even be another array.

     Since _itemArrayGet() creates a new item reference, do not forget to
     release the new reference with _itemRelease() after use.  Failure to do
     so could result in a CA-Clipper stack fault.

     Note:  Since CA-Clipper arrays are one-based, not zero-based, the
     uiElem parameter must not be zero.

 Examples

     /*
     * MYACLONE()
     * ----------
     * myAClone( <aArray1> ) --> aNewArray
     */

     HIDE ITEM near _xAClone( ITEM aSrc );

     CLIPPER ARRAYCLONE( void )

     {
        ITEM aSource;            // Source array
        ITEM aCloned;            // New array

        /* Do parameters check */

        if ( PCOUNT != 1 )
        {
           return;
        }

        /* Get source array as ITEM */

        aSource = _itemParam( 1 );

        /* Clone source array  */

        aCloned = _xAClone( aSource );

        /* Return clone, release clone and source */

        _itemReturn ( aCloned );

        _itemRelease( aSource );
        _itemRelease( aCloned );

        return;
     }

     HIDE ITEM near _xAClone( ITEM aSrc )
     {
        ITEM   temp;
        ITEM   aTemp;
        ITEM   aNew;

        USHORT i;
        USHORT nLen;

        // If item not an array, return NIL
        if ( !( _itemType( aSrc ) == ARRAY ) )
           return ( _itemNew( NULL ) );

        // Get number of elements, create new array
        nLen = _itemSize( aSrc );
        aNew = _itemArrayNew( nLen );

        // For each element... get source & copy
        for ( i = 1; i <= nLen; i++ )
        {
           temp = _itemArrayGet( aSrc, i );

           // If it's an array, copy via recursion
           if ( _itemType( temp ) == ARRAY )
           {
              aTemp = _xAClone( temp );
              _itemArrayPut( aNew, i, aTemp );
              _itemRelease( aTemp );
           }
           else
           {
              _itemArrayPut( aNew, i, temp );
           }

           _itemRelease( temp );

        }

        return ( aNew );

     }

 Files  Library is CLIPPER.LIB, header file is Item.api.


See Also: _itemArrayNew() _itemArrayPut() _itemRelease()

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