Compartir a través de


_NameTableIndex( ) API Library Routine

Returns the name table index that corresponds to a given name, or returns – 1 if that name isn't in the name table.

NTI _NameTableIndex(char FAR *name)
char FAR *name;            /* Name. */

Remarks

The name may be found in the name table even though a variable with the name name doesn't exist. To determine whether a variable with the name name exists, use _FindVar( ), specifying the name table index returned by _NameTableIndex( ) as the nti parameter.

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 releases a memory variable whose name is given as a character argument. Note that _NameTableIndex( ) finds the variable name after it has been released. Therefore, _NameTableIndex( ) is used in combination with _FindVar( ) to make sure the memory variable is currently defined.

Visual FoxPro Code

SET LIBRARY TO NTI    
x = 123
= XRELEASE("x")

C Code

#include <pro_ext.h>

FAR ReleaseEx(ParamBlk FAR *parm)
{
   NTI nti;
   char FAR *name;
   int exitCode;
   Locator loc;

   //   Null terminate character string, name of variable
   if (!_SetHandSize(parm->p[0].val.ev_handle,
      parm->p[0].val.ev_length+1))
   {
      _Error(182); // "Insufficient memory"
   }
   _HLock(parm->p[0].val.ev_handle);
   name = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle);
   name[parm->p[0].val.ev_length] = '\0';

   if ((nti = _NameTableIndex(name)) == -1)
   {
      _HUnLock(parm->p[0].val.ev_handle);
      _UserError("Cannot find variable in name table.");
   }
   _HUnLock(parm->p[0].val.ev_handle);

   if (_FindVar(nti, -1, &loc))
   {
      _PutStr("\nVariable exists prior to _Release().");
   }
   if ((exitCode =_Release(nti)) < 0)
   {
      _Error(-exitCode);
   }

   _HLock(parm->p[0].val.ev_handle);
   name = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle);
   name[parm->p[0].val.ev_length] = '\0';

   if ((nti = _NameTableIndex(name)) != -1)
   {
      _PutStr("\n_NameTableIndex() still finds variable \
         after it is released.");
   }
   _HUnLock(parm->p[0].val.ev_handle);

   if (!_FindVar(nti, -1, &loc))
   {
      _PutStr("\nVariable does not exist after _Release().");
   }
}

FoxInfo myFoxInfo[] = {
   {"XRELEASE", (FPFI) ReleaseEx, 1, "C"},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

See Also

Concepts

API Library Routines A-Z

Reference

_ALen( ) API Library Routine

_FindVar( ) API Library Routine

_Load( ) API Library Routine

_NewVar( ) API Library Routine

_ObjectRelease( ) API Library Routine

_Store( ) API Library Routine

Other Resources

Accessing the Visual FoxPro API

API Library Routines by Category