Evaluate Function

Applies to TestComplete 15.69, last modified on November 13, 2024

The Evaluate function evaluates an expression.

Declaration

Evaluate(Expression) Parameters
Expression [in] Required String
Result     Variant  

Description

Evaluates the expression specified in the Expression string and returns the evaluation result. For instance, Evaluate('5 + 5') returns 10; Evaluate('Sys.Desktop.ActiveWindow') returns the window object that corresponds to the current top-level window.

Parameters

The procedure has the following parameter:

Expression

Specifies the expression to be evaluated.

Return Value

The result of the evaluation.

Remarks

The Evaluate function fails when evaluating an expression that includes a procedure, for example, a routine without a return value, but does not specify the name of the unit containing the procedure.

Example

The example below demonstrates the wrong usage of the Evaluate function. If you run the TestEval procedure as shown in this code, it will fail.

DelphiScript

procedure PostMessage;
begin
  Log.Message('Success');
end;

procedure TestEval;
begin
  Evaluate('PostMessage');
end;

The example below demonstrates the correct use of the Evaluate function when evaluating a procedure declared in the current unit (for example, Unit1).

DelphiScript

// Both procedures are declared in the same unit, for example, Unit1
procedure PostMessage;
begin
  Log.Message('Success');
end;

procedure TestEval;
begin
  Evaluate('Unit1.PostMessage');
end;

The example below demonstrates the correct use of the Evaluate function when evaluating a procedure declared in another unit (for example, Unit2). In this case the unit that contains the evaluating procedure must be specified in the uses section of the executed procedure.

DelphiScript

// This procedure is declared in the Unit2 unit
procedure PostMessage;
begin
  Log.Message('Success');
end;

// This procedure is specified in another unit, for example, Unit1
uses Unit2;
procedure TestEval;
begin
  Evaluate('Unit2.PostMessage');
end;

See Also

DelphiScript - List of Supported Routines and Variables

Highlight search results