[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _itemSize()
 Determine an item's size
------------------------------------------------------------------------------
 C Prototype

     #include "item.api"
     USHORT _itemSize(
                       ITEM itmRef
                     )

 Arguments

     itmRef is the item whose size you want to determine.

 Returns

     _itemSize() returns an unsigned short integer value indicating the size
     of the item referenced by itmRef.

 Description

     The _itemSize() function returns the storage size required for a
     particular item.  For each CA-Clipper data type, length is determined
     according to the table below:

     Return Size for Each Item Type
     ------------------------------------------------------------------------
     Item Type                  Size Returned
     ------------------------------------------------------------------------
     ARRAY                      Number of elements in array.
     CHARACTER or MEMO          Storage length of the string.
     UNDEF                      Always returns zero.
     ------------------------------------------------------------------------

     Note:  Size is determined from a one base, not zero, as are most
     programming structures in C.  Thus, an array that has an _itemSize() of
     42 actually contains 42 elements, and not 43 as one might expect.  An
     array of length zero, however, may exist.

 Examples

     /*
     *
     * CharCount( cString, cChar )
     *
     * Count occurrences of a single character
     * in a CA-Clipper string.
     *
     */

     CLIPPER CharCount( void )
     {
        USHORT uiChars = 0;
        USHORT uiLen;
        USHORT i;
        HANDLE vmhString;

        BYTEP  cStringP;
        BYTE   cFindMe;

        ITEM   itmString, itmFindMe, itmRet;

        if (PCOUNT != 2)
        {
           _ret();               // NOTE: Withhold service
           return;               // Early return!
        }

        itmRet    = _itemPutNL( NULL, 0 );
        itmString = _itemParam( 1 );
        itmFindMe = _itemParam( 2 );

        if ( (_itemType( itmString ) == CHARACTER) &&
              (_itemType( itmFindMe ) == CHARACTER) )
        {
           _itemCopyC( itmFindMe, &cFindMe, 1 );

           vmhString = _xvalloc( _itemSize( itmString ), NULL );
           cStringP = _xvlock( vmhString );

           uiLen = _itemCopyC( itmString, cStringP, NULL );

           for( i = 0; i < uiLen; i++ )
           {
              if ( cStringP[i] == cFindMe )
                 uiChars++;
           }

           _xvunlock( vmhString );
           _xvfree( vmhString );

           itmRet = _itemPutNL( itmRet, (long)uiChars );

        }

        _itemReturn( itmRet );

        _itemRelease( itmRet );
        _itemRelease( itmString );
        _itemRelease( itmFindMe );

        return;
     }

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


See Also: _itemType()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson