Click or drag to resize

MExec Function

X#
Evaluate a macro-compiled string.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
[NeedsAccessToLocalsAttribute(TRUE)]
 FUNCTION MExec(
	oBlock AS Codeblock
) AS USUAL
Request Example View Source

Parameters

oBlock
Type: Codeblock
The macro-compiled string.

Return Value

Type: Usual
The value of the compiled expression.
Remarks
MExec() evaluates an expression that was previously macro-compiled. Instead of invoking the macro compiler each time an expression is evaluated, you could speed up your application by compiling an expression only once and executing the compiled result as often as desired.
Tip Tip
In Visual Objects the return value of MCompile() is a specially formatted string with PCode tokens. We have changed that in X#, and the return value of MCompile() is now a codeblock of the _Codeblock type.
If the string that was compiled in Visual Objects was in the form of "{||.....}" then you hed to call MExec() to convert the string into a _Codeblock object. To evaluate the codeblock you would then have to pass the result of MExec() into the EVal() function.
If the string that was compiled in Visual Objects was not in the form of "{||.....}", like in the examples of this topic then calling MExec() on return value of MCompile() would immediately evaluate the expression and return the result.
Since in X#the return the return value of MCompile() is a codeblock of the _Codeblock type, you can you can also use the Eval() function to evaluate the codeblock.
In X# Calling MExec() on the codeblock returned from MCompile() will either directly evaluate the codeblock (when the original string was not in the codeblock format) or will simply return the same codeblock when the original string was in the codeblock format.
Examples
This examples show typical uses of MCompile() and MExec():
X#
 1LOCAL cComp AS CodeBlock        // Note that this had to be string in Visual Objects
 2cComp := MCompile("2+3")
 3? MExec(cComp)                  // 5
 4nResult := MExec(cComp)         // Assigning
 5? MExec(cComp) = 5              // Comparing
 6MEMVAR Two // Declare and initialize a Private variable
 7Two := 2
 8cComp := MCompile("Two+3")      // Macro refers to the private variable
 9? MExec(cComp)                  // 5
10// The followin works in X# only, since the result of cComp is now a CodeBlock
11? Eval(cComp)
See Also