TMtxExpression.Evaluate Method

Overload List

#SignatureDescription
1function Evaluate: TValueRec;Evaluates all expressions from the list.
2function Evaluate(Index: Integer): TValueRec;Evaluates expression at the specified index.

Overload 1: function Evaluate: TValueRec;

Evaluates all expressions from the list.

Returns: TValueRec - result of the latest expression.

See Also: TMtxExpression.EvaluateDouble, TMtxExpression.EvaluateComplex, TMtxExpression.EvaluateVector, TMtxExpression.EvaluateMatrix

Overload 2: function Evaluate(Index: Integer): TValueRec;

Evaluates expression at the specified index.

#NameTypeDescription
1IndexIntegerstart index

Returns: TValueRec - result of the expression, evaluated at specific index.

Remarks:

If the Index parameter is specified to be -1, the method will evaluate all expressions in the list starting with the first and return the result of the last expression in the list.

The function returns TValueRec. This object contains information about the type of the result and the result itself. To determine the type read the TValueRec.ValueType property.

The types in the expression are resolved at compile time and may not change after the first call to the Evalute function. The result of a given expression will therefore always have the same type.

This allows for omission of certain checks and further increase of code speed. Instead of calling EvaluateDouble method, it would be faster to call just:

myDouble := myParser.Evaluate.DoubleValue;

,if you know that the result of the expression is a variable of type double.

Examples
uses MtxParseExpr, MtxParseClass;

function TMtxExpression.EvaluateDouble(Index :integer): Double;
var vr :TValueRec;
begin
    vr:= Evaluate(Index);
    case vr.ValueType of
        vtDoubleValue:
            begin
                result:= vr.DoubleValue;
                Exit;
            end;
        vtComplexValue:
            if vr.ComplexValue.Im = 0 then begin
                result:= vr.ComplexValue.Re;
                Exit;
            end;
    end;
    raise EMtxParseError.Create ('TMtxExpression.EvaluateDouble: double value expected');
end;
See Also: TMtxExpression.EvaluateDouble, TMtxExpression.EvaluateComplex, TMtxExpression.EvaluateVector, TMtxExpression.EvaluateMatrix