Freigeben über


_FindVar( ) API Library Routine

Provides a way to initialize a Locator so you can use _Store( ) to place data in an existing memory variable or field.

int _FindVar(NTI nti, int where, Locator FAR *loc)
NTI nti;                     /* NTI number of variable or field. */
int where;                  /* Work area number. */
Locator FAR *loc;            /* Locator. */

Remarks

_FindVar( ) fills in the passed Locator with information about a variable or field named nti that exists in a work area specified by where.

  • If where is – 1, nti is assumed to be a memory variable.
  • If where is 1 – 225, nti is assumed to be a field in the work area of the specified number.
  • If where is 0, _FindVar first checks to see if nti is a memory variable. If it's not a memory variable, the current work area is checked for a field with the specified NTI.

_FindVar( ) returns True (an integer other than 0) if a variable or field nti is found in where; otherwise, _FindVar( ) returns False (0).

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 displays the value of a Visual FoxPro variable in a very roundabout way.

Visual FoxPro Code

SET LIBRARY TO FINDVAR 
TestVar= "This is a test"
= QMARK("TestVar")

C Code

#include <pro_ext.h>

void putLong(long n)
{
   Value val;

   val.ev_type = 'I';
   val.ev_long = n;
   val.ev_width = 10;

   _PutValue(&val);
}

FAR NameTableIndexEx(ParamBlk FAR *parm)
{
   NTI nti;
   char FAR *name;
   Locator loc;
   Value val;

//   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';

   nti = _NameTableIndex(name);

   _FindVar(nti, 0, &loc);
   _Load(&loc, &val);
   _PutValue(&val);
}

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

See Also

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