IExpression.ThrowException

Syntax

ThrowException: Boolean;

Description

The ThrowException property determines whether an exception is thrown when a parsed expression contains errors.

Comments

Available values:

Regardless of the property value, if an error occurred while parsing the expression, this error is available in the IExpressionErrorInfo.Exception property.

Example

Executing the example requires a form, buttons named Button1 and Button2 on the form, and the ExpressionEdit component named ExpressionEdit1. The repository contains a table with the Table_1 identifier. The last field of the table is a calculated field.

The example is a handler of the OnClick event for the Button1 and Button2 components.

Add links to the Db, ExtCtrls, Forms, Metabase, and Ui system assemblies.

Class TestForm: Form
    Button1: Button;
    Button2: Button;
    ExpressionEdit1: ExpressionEdit;
    Tab: ITable;
    Field: ITableField;

// Connect the ExpressionEdit1 component to table calculated field expression   
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    MB: IMetabase;
Begin
    MB := MetabaseClass.Active;
    Tab := MB.ItemById("Table_1").Edit As ITable;
    Field := Tab.Fields.Item(Tab.Fields.Count - 1);
    ExpressionEdit1.Expression := Field.Expression;     
End Sub Button1OnClick;

// Check if entered expression is correct for use in table calculated field
Sub Button2OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    Expr: IExpression;
    ErrInfo: IExpressionErrorInfo;
Begin
    Expr := ExpressionEdit1.Expression;
    Expr.ThrowException := False;
    Expr.AsString := ExpressionEdit1.Formula;
    If Not Expr.Valid Then
    ErrInfo :=Expr.ErrorInfo;
    WinApplication.ErrorBox("An error occurred on expression parsing: " + ErrInfo.ErrorMessage + "." + #10 + #13 + "Position: " + ErrInfo.Position.ToString);
    Else
        Field.Expression.AsString := Expr.AsString;
        (Tab As IMetabaseObject).Save;
    End If;
End Sub Button2OnClick;

End Class TestForm;

On executing the form the ExpressionEdit1 component is connected to the expression of the calculated field after the Button1 button is clicked. After the expression is edited in the ExpressionEdit1 component and the Button2 is clicked, the system checks if the expression is correct for use in the table calculated field. If the expression is valid, it is updated in the calculated field of the table, and the table is saved. If the expression is invalid, an error message is displayed indicating text and the number of the position where the error occurred. No platform exception is thrown if the expression is invalid.

See also:

IExpression