_Release( ) API Library Routine 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.
SET LIBRARY TO RELEASE
x = 123
= XRELEASE("x")
#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
};