IMetabaseCodeBlock.Execute

Syntax

Execute(SubName: String; Params: Array): Variant;

Parameters

SubName. Name of the method to be executed.

Params. Parameters required for execution.

Description

The Execute method executes code block on Fore and returns execution result.

Example

Executing the example requires that the repository contains an assembly with the ASM_CORE identifier. The assembly contains a module where the GenerateNumber function is implemented.

Add a link to the Metabase system assembly.

Sub UserProc;
Var
    Mb: IMetabase;
    CodeBlock: IMetabaseCodeBlock;
    Result: Variant;
Begin
    Mb := MetabaseClass.Active;
    CodeBlock := Mb.CreateCodeBlock;
    CodeBlock.References := 
"MathFin;ASM_CORE";
    CodeBlock.Text :=
        
"Function Test(x, y: Integer): Integer;" + #13 + #10 +
        
"Var" + #13 + #10 +
        
"   n: Integer;" + #13 + #10 +
        
"Begin" + #13 + #10 +
        
"   n := GenerateNumber;" + #13 + #10 +
        
"   If (n>x) And (n<y) Then" + #13 + #10 +
        
"      Return Math.Int((y-x)/n);" + #13 + #10 +
        
"   Else" + #13 + #10 +
        
"      Return Math.Int(n/(y-x));" + #13 + #10 +
        
"   End If" + #13 + #10 +
        
"End Function Test;";
    
If CodeBlock.Valid Then
        Result := CodeBlock.Execute(
"Test"110);
        Debug.WriteLine(Result);
    
Else
        Debug.WriteLine(
"While code compilation an error appeared.");
        Debug.WriteLine(
"Error text: " + CodeBlock.ErrorMessage);
        Debug.WriteLine(
"String: " + CodeBlock.Line.ToString);
        Debug.WriteLine(
"Position: " + CodeBlock.Position.ToString);
    
End If;
    
Dispose CodeBlock;
End Sub UserProc;

On executing the example an object that executes a block of code on Fore is created. An executed code is assigned and it checks on syntax. If the code does not have mistakes, it is executed. Execution is performed with specified parameters values. The execution result will be contained in the Result variable and displayed to the development environment console. If the code has errors, the text of error and location of its appearing is displayed into development environment console. To execute the code, the MathFin system assembly and the ASM_CORE custom assembly are connected.

See also:

IMetabaseCodeBlock