Share via


_Release( ) API Library Routine

Releases from memory the specified memory variable or array.

int _Release(NTI n)
NTI n;                     /* NTI number of variable or array
 to release. */

Remarks

_Release( ) returns 0 if it successfully releases the memory variable or array, or an integer whose absolute value is a Visual FoxPro error number if it fails.

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. _NameTableIndex( ) is used to find the NTI of the variable.

Visual FoxPro Code

SET LIBRARY TO RELEASE 
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

Reference

_ALen( ) API Library Routine

_RetCurrency( ) API Library Routine

_RetDateTimeStr( ) API Library Routine

_FindVar( ) API Library Routine

_Load( ) API Library Routine

_NameTableIndex( ) API Library Routine

_NewVar( ) API Library Routine

_Store( ) API Library Routine

Other Resources

API Library Construction