IExpressionErrorInfo.Position

Syntax

Position: Integer;

Description

The Position property returns the number of end position of the element that caused error in the expression.

Example

Executing the example requires a form, two buttons on this form and named Button1 and Button1and 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 the 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:

IExpressionErrorInfo