IExpression.StringHandler

Syntax

StringHandler: IExpressionStringHandler;

Description

The StringHandler property determines an object that is used to track changes of expression terms.

Comments

The property value must be specified as an instance of the custom class implementing methods of the IExpressionStringHandler interface.

Example

Executing the example requires a form, buttons named Button1 and Button2 on it, and the ExpressionEdit component named ExpressionEdit1. The repository contains a table with the CalcTable identifier. The table structure contains the VAL1, VAL2, and CHECKVALUE fields. The CHECKVALUE field is a calculated field.

Class TESTForm: Form
    Button1: Button;
    Button2: Button;
    ExpressionEdit1: ExpressionEdit;

    Sub TESTFormOnCreate(Sender: Object; Args: IEventArgs);
    Var
        MB: IMetabase;
        Tab: ITable;
    Begin
        MB := MetabaseClass.Active;
        Tab := MB.ItemById("CalcTable").Bind As ITable;
        ExpressionEdit1.Expression := Tab.Fields.FindById("CHECKVALUE").Expression;
    End Sub TESTFormOnCreate;

    Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
    Var
        Expression: IExpression;
    Begin
        Expression := ExpressionEdit1.Expression;
        //Set event handler
        Expression.StringHandler := New StrHandler.Create;
        //Specify new formula
        ExpressionEdit1.Formula := "Iif(VAL1 = VAL2, 0, Iif(VAL1 > VAL2, 1, -1))";
        //Update expression in ExpressionEdit1.Expression according to specified formula
        ExpressionEdit1.UpdateExpression;
    End Sub Button1OnClick;

    Sub Button2OnClick(Sender: Object; Args: IMouseEventArgs);
    Begin
        Debug.WriteLine("Expression: " + ExpressionEdit1.Expression.AsString);
    End Sub Button2OnClick;
End Class TESTForm;

Class StrHandler: Object, IExpressionStringHandler
    Sub OnTerm(Text: String);
    Begin
        Debug.WriteLine("Term: " + Text);
    End Sub OnTerm;

    Sub OnText(Text: String);
    Begin
        Debug.WriteLine("Text: " + Text);
    End Sub OnText;
End Class StrHandler;

When the form is loaded, the ExpressionEdit1 component is connected to the expression, according to which values of the CHECKVALUE calculated field are calculated. Clicking the first button the component expression is subscribed to the StrHandler event handler, a new formula is set, and component contents is updated. During the update, terms are parsed, after which the OnTerm event is generated. After executing the UpdateExpression method the ExpressionEdit1.Expression component expression will correspond with the ExpressionEdit1.Formula formula. Clicking the second button displays the component expression in the development environment console. When the expression is addressed, it is also parsed, after which the OnTerm and OnText events are generated.

See also:

IExpression