_NameTableIndex( ) API Library Routine

JavaScript Editor js editor     Web development 



Main Page

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

В Copy Code
SET LIBRARY TO NTI    
x = 123
= XRELEASE("x")

C Code

В Copy 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



JavaScript Editor js editor     Web development