次の方法で共有


_ALen( ) API Library Routine

Returns information about the dimensions of the array whose name table index is nti.

long _ALen(NTI nti, int mode)
NTI nti;                     /* Array name table index. */
int mode;                     /* Mode to determine return value. */

Remarks

If mode is AL_ELEMENTS, _ALen( ) returns the total number of elements in the array. If mode is AL_SUBSCRIPT1, _ALen( ) returns the value of the first subscript used to declare the array. If mode is AL_SUBSCRIPT2, _ALen( ) returns the value of the second subscript used to declare the array.

If nti doesn't represent the name of an existing array, _ALen( ) returns – 1 regardless of the value of mode.

For more information on how to create an API library and integrate it with Visual FoxPro, see Accessing the Visual FoxPro API.

Example

The following example provides a Visual FoxPro API routine for each of the three possible mode values.

Visual FoxPro Code

SET LIBRARY TO ALEN  
DIMENSION a[10, 11]
? ALENELEM(@a)  && returns 110
? ALENSUB1(@a)  && returns 10
? ALENSUB2(@a)  && returns 11

DIMENSION b[3]
? ALENELEM(@b)  && returns 3
? ALENSUB1(@b)  && returns 3
? ALENSUB2(@b)  && returns 0; no second subscript

c = .F.
? ALENELEM(@c)  && returns -1 because variable "c" is not an array
? ALENSUB1(@c)  && returns -1 because variable "c" is not an array
? ALENSUB2(@c)  && returns -1 because variable "c" is not an array

C Code

#include <pro_ext.h>

void FAR alenElem(ParamBlk FAR *parm)
{
   _RetInt(_ALen(parm->p[0].loc.l_NTI, AL_ELEMENTS), 10);
}

void FAR alenSub1(ParamBlk FAR *parm)
{
   _RetInt(_ALen(parm->p[0].loc.l_NTI, AL_SUBSCRIPT1), 10);
}

void FAR alenSub2(ParamBlk FAR *parm)
{
   _RetInt(_ALen(parm->p[0].loc.l_NTI, AL_SUBSCRIPT2), 10);
}

FoxInfo myFoxInfo[] = {
   {"ALENELEM", (FPFI) alenElem, 1, "R"},
   {"ALENSUB1", (FPFI) alenSub1, 1, "R"},
   {"ALENSUB2", (FPFI) alenSub2, 1, "R"},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

See Also

_FindVar( ) API Library Routine | _Load( ) API Library Routine | _NameTableIndex( ) API Library Routine | _NewVar( ) API Library Routine | _ObjectRelease( ) API Library Routine | _Store( ) API Library Routine