PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US

  • Local variables
  • Compiling the expression
  • Using a procedure of external component
  • Dynamic code
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
EvaluateExpression (Function)
In French: EvalueExpression
Evaluates the value of an expression built in a character string.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Example
// Evaluate a formula
x,y are real
x = 1.5
y = 5
Trace(EvaluateExpression("cos(x)+sin(y)"))
Syntax
<Result> = EvaluateExpression(<Expression>)
<Result>: Any type
  • If the expression compiles without any errors, result of the expression.
  • If the expression fails to compile, if it does not return a value or if an error occurs during the evaluation, it triggers a fatal error.
<Expression>: Character string (with quotes)
Expression to evaluate.
Remarks

Local variables

The local variables of the current process can be used directly in the expression.

Compiling the expression

The code is recompiled whenever EvaluateExpression is called.
To avoid the compilation step, you can use Compile and Execute to build the code of a procedure, compile it once and run it several times. In this case, you will lose the ability to directly use local variables of the current process which will need to be replaced by parameters in the procedure.

Using a procedure of external component

The code is recompiled whenever EvaluateExpression is called.
The call to a procedure of external component must name this procedure with its full name.
EvaluateExpression("MyComponent.MySet.MyProcedure()"))

Dynamic code

If the source code used for the dynamic compilation contains names of files, items, controls, windows, reports, queries, ... these names must necessarily be enclosed in quotes.
For example, you must use: HReadFirst("Customer", "Name") instead of HReadFirst(Customer, Name)
The constants cannot be used in the dynamic code (defined by the CONSTANT keyword).
When using constants in a code, all the occurrences of the constants are replaced by their value during the compilation in the editor but the correspondence between the name of constants and their value is not "embedded" in the application. Therefore, the dynamic compilation cannot use the constants.
Let's see two alternatives:
1 - Use variables instead of constants:
CONSTANT
CST_Name = 1
END
becomes for example
CST_Name is int = 1
or
2 - In the string containing the code that must be compiled dynamically, replace the name of the constant by its value:
sCode is string
// In the string containing the code that will be compiled dynamically
// instead of leaving the name of the constant:
sCode=[
Info(CST_Name)
]
// Replace the name of the constant by its value
sCode = Replace(sCode, "CST_Name", CST_Name, WholeWord + IgnoreCase)
// The code can be compiled now
IF Compile("DynProc", sCode) <> "" THEN
Error("Error while compiling the dynamic procedure: ", ...
ErrorInfo())
ELSE
// Then it can be run
WHEN EXCEPTION IN
ExecuteProcess("DynProc", trtProcedure)
DO
Error("Error while running the dynamic procedure: ", ...
ExceptionInfo())
END
END
Components
WINDEVWEBDEV - Server codeReports and Queries wd230vm.dll
Windows Mobile wp230vm.dll
Linux wd230vm.so
Minimum required version
  • Version 17
This page is also available for…
Comments
Click [Add] to post a comment