_Evaluate( ) API Library Routine

Compiles and executes a Visual FoxPro expression you specify with expr, placing the result in res.

int _Evaluate(Value FAR *res, char FAR *expr)
Value FAR *res;            /* Address for result. */
char FAR *expr;            /* Expression. */

Remarks

You can specify any expression that can be evaluated by the Visual FoxPro EVALUATE( ) function. After the expression is evaluated, control usually returns to the C statement immediately following the call to _Evaluate( ). Exceptions include evaluating a Visual FoxPro expression that carries out a Visual FoxPro CANCEL or QUIT command.

_Evaluate( ) returns the Visual FoxPro internal error number for any errors that occur during evaluation of the Visual FoxPro expression, or returns 0 if no errors occur. The contents of res are valid only when _Evaluate( ) returns a value of 0.

Note   Do not call _Evaluate( ) from an event handler.

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 has the same functionality as the Visual FoxPro EVALUATE( ) function.

Visual FoxPro Code

SET LIBRARY TO EVALUATE
? XEVAL("2 + 3")
? XEVAL("'a' + 'b'")
? XEVAL("SIN(PI()/2))")

C Code

#include <pro_ext.h>

FAR EvaluateEx(ParamBlk FAR *parm)
{
   char FAR *expr;
   Value result;

//   Null terminate character string
   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);
   expr = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle);
   expr[parm->p[0].val.ev_length] = '\0';

   _Evaluate(&result, expr);
   _RetVal(&result);

   _HUnLock(parm->p[0].val.ev_handle);
}

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

See Also

_Execute( ) API Library Routine | CANCEL Command | QUIT Command | Accessing the Visual FoxPro API