Class wwEval

Executing objects safely by wrapping an error handler around any foreign execution.

This class can be used to execute code that is of unknown or variable such as code stored in memo fields and run later, or code stored in script pages and evaluated on the fly. These types of environments require a safety wrapper to make sure that any of this 'external' code doesn't crash the core application.

How it works

The wwEval class implements methods that allow you to:

  • Evaluate a FoxPro expression
  • Execute a single FoxPro command
  • Run a CodeBlock in fully interpreted mode at runtime (using CodeBlock)
  • Merge a document containing expressions and code blocks (scripting)

All of these operations are implemented as methods of the wwEval class. The class contains an error method which traps these errors and records the error information. Upon return from the execution the calling code can check for errors by checking the lError flag and the cErrorMessage property.

Class Members

MemberDescription

EvalTimer

A simple way to fire a timer and execute an expression or code block. Set a delay and specify how often to repeat the timer execution.

EvalTimer(lcExpr,lnMilliseconds,lnRepeat,lnMode,lvState, lvState1,lvState2)

Evaluate

Evaluates an expression. This method simply does an EVALUATE() with some provisions for error handling.

o.Evaluate(lcEvalString)

EvaluateClassMethod

Executes a method inside of a class.

o.EvaluateClassMethod(lcClass, lcMethod, lcClassLib)

Execute

Executes a block of code using ExecScript() providing exception handling and error information.

o.Execute(lcCode)

ExecuteCommand

Excecutes a single FoxPro command safely.

o.ExecuteCommand(lcEvalString)

MergeText

MergeText is a template expansion method that can be used to 'merge' text into a document. The most common use you may be familiar with is for Web scripting where Active Server Style tags can be used to embed FoxPro code and expressions into an output stream.

o.MergeText(tcString,tcDelimiter, tcDelimiter2, llNoASPSyntax)

cErrorMessage

Error Message if an error occurred.

cResultType

On return from an execution method this property contains the type of the result value.

lAllowEvalRecursion

Determines if the MergeText function allows recursive expression. So if an expression returns another set of markup expressions (Visual FoxPro 09.00.0000.7423 EXE Support Library for Windows) by default the expanded expression is not evaluated.

lError

Error flag set when an error occurs. cErrorMessage and nErrorNo contain further info on the error.

nError

The error number if an error occurred. Only valid if lError is .T.

nErrorLine

The line the error occurred on.

Result

Contains the result value of the last executed command if the call succeeded. Typically you don't need to check this value since it will be returned as part of the method call so you can use it directly.

vErrorResult

You can pre-set the error result value. When an error occurs the result value from the code/expression will return this value when an error occurs.

Requirements

Assembly: wwEval.prg

© West Wind Technologies, 2024 • Updated: 01/09/16
Comment or report problem with topic