ThrowException: Boolean;
The ThrowException property determines whether an exception is thrown when a parsed expression contains errors.
The property is set to True by default. If an error occurs when parsing the expression, a platform exception is thrown that is to be handled using the Try … End Try operator.
If the False value is set for this property, no exception is thrown when parsing an incorrect expression. Use the Valid property to check if the expression is correct.
Regardless of the property value, if an error occurred while parsing the expression, this error is available in the Exception property.
Executing the example requires a form, two buttons located on this form and named Button1 and Button1, and also 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.
Class TestForm: Form
Button1: Button;
Button2: Button;
ExpressionEdit1: ExpressionEdit;
MB: IMetabase;
Tab: ITable;
Field: ITableField;
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
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;
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 while parsing the expression: "
+ 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 this form the ExpressionEdit1 component is connected to the expression of the calculated field of the table 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 valid to be used in the calculated table 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: