- Local variables
- Compiling the code
- Dynamic code
In french: ExecuteCode
Runs the WLanguage code found in a character string.
sText is string = "Text"
// Displays the text in a window
// Declare the variables.
sCodeToRun is string
xOperationResult is numeric
// WLanguage code to run.
// This code returns the result of an operation %1.
sCodeToRun = [
MyCalculation is numeric
MyCalculation = %1
// WLanguage code to run.
// Replace %1 by the operation displayed
// in the EDT_EXPRESSION edit control.
sCodeToRun = StringBuild(sCodeToRun, EDT_EXPRESSION)
// Run the code and retrieve the result.
xOperationResult = ExecuteCode(sCodeToRun)
// Displays the result of the operation in an Info message box
Info("The result of your operation is: " + xOperationResult)
<Result> = ExecuteCode(<Code>)
<Result>: Any type
- Result of the code if it contains a RETURN statement,
- Nothing otherwise. In this case, an error message may be displayed when the result is assigned in a variable for example.
<Code>: Character string
WLanguage code to run.
Remark: This code may contain the call and declaration code of an internal procedure.
The local variables of the current process can be directly used in the code to run.
If the code is compiled without error, the code is run directly.
A fatal error is triggered if the code is not compiled.
Compiling the code
The code is recompiled each time ExecuteCode is called.
To avoid the compilation step, you have the ability to use Compile
The constants cannot be used
in the dynamic code (defined by the CONSTANT
When using constants in a code, all the occurrences of the constants are replaced with 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
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:
// 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: ", ...
// Then it can be run
WHEN EXCEPTION IN
Error("Error while running the dynamic procedure: ", ...
This page is also available for…