CreateDocumentFormulaParser: IPrxDocumentExpressionParser;
CreateDocumentFormulaParser(): Prognoz.Platform.Interop.Report.IPrxDocumentExpressionParser;
The CreateDocumentFormulaParser method creates an object that parses expression of the formula specified on a regular report text sheet.
To get the collection of regular report sheets, use the IPrxReport.Sheets property.
Executing the example requires that the repository contains a regular report with the DOCUMENT identifier. The report contains the Document1 text sheet that includes at least one text box.
Add links to the Drawing, Metabase, Report system assemblies.
Sub UserProc;
Var
MB: IMetabase;
MObj: IMetabaseObject;
Report: IPrxReport;
Doc: IPrxDocument;
DocExpr: IPrxDocumentExpression;
Style: IPrxCellStyle;
DataSource: IPrxDataSource;
Points: IPrxCalculatedPoints;
Point: IPrxCalculatedPoint;
Parser: IPrxDocumentExpressionParser;
Term: String;
Expr: IExpression;
Begin
MB := MetabaseClass.Active;
MObj := MB.ItemById("DOCUMENT").Edit;
Report := MObj As IPrxReport;
Doc := Report.Sheets.FindByName("Document1") As IPrxDocument;
// Expression:
DocExpr := Doc.DocumentExpressions.Item(0);
Style := DocExpr.Style;
Style.BackgroundBrush := New GxSolidBrush.Create(GxColor.FromName("Blue"));
Debug.WriteLine("Number of calculated fields on sheet: " + Doc.DocumentExpressions.Count.ToString);
Debug.WriteLine("Calculated field expression: " + DocExpr.Expression.AsString);
Debug.WriteLine("Value: " + DocExpr.Value);
Debug.WriteLine("Formatted value: " + DocExpr.FormattedValue);
// Parse formula expression:
DataSource := Report.DataSources.Item(0);
Points := DataSource.Points;
Point := Points.Item(0);
Parser := Report.CreateDocumentFormulaParser;
Parser.ClearTerms;
Parser.DocumentExpression := DocExpr;
Term := Parser.AddTerm;
Parser.TermType(Term) := PrxDocumentExpressionTermType.PointType;
Parser.TermPointKey(Term) := Point.Key;
Parser.TermSourceKey(Term) := 1;
Parser.TermText(Term) := "Point1";
Expr := Parser.Formula;
Parser.Parse(Expr.AsString);
Debug.WriteLine("Number of terms: " + Parser.TermCount.ToString);
Debug.WriteLine("Term with the 0 index: " + Parser.Term(0));
(Report As IMetabaseObject).Save;
End Sub UserProc;
After executing the example the console window displays:
Number of calculated fields on the text sheet of the specified regular report.
Calculated field expression.
Value and formatted value of calculated field.
Total number of terms.
Value of the term with the 0 index.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Add links to the Drawing, ForeSystem, Metabase, Report system assemblies.
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Report;
Imports Prognoz.Platform.Interop.Drawing;
Imports Prognoz.Platform.Interop.ForeSystem;
…
Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
MObj: IMetabaseObject;
Report: IPrxReport;
Doc: IPrxDocument;
DocExpr: IPrxDocumentExpression;
Style: IPrxCellStyle;
ColorCls: GxColorClass = New GxColorClassClass();
Brush: GxSolidBrush = New GxSolidBrushClass();
DataSource: IPrxDataSource;
Points: IPrxCalculatedPoints;
Point: IPrxCalculatedPoint;
Parser: IPrxDocumentExpressionParser;
Term: String;
Expr: IExpression;
Begin
MB := Params.Metabase;
MObj := MB.ItemById["DOCUMENT"].Edit();
Report := MObj As IPrxReport;
Doc := Report.Sheets.FindByName("Document1") As IPrxDocument;
// Expression:
DocExpr := Doc.DocumentExpressions.Item[0];
Style := DocExpr.Style;
Brush.Create(ColorCls.FromName("Blue"));
Style.BackgroundBrush := Brush;
System.Diagnostics.Debug.WriteLine("Number of calculated fields on sheet: " + Doc.DocumentExpressions.Count.ToString());
System.Diagnostics.Debug.WriteLine("Calculated field expression: " + DocExpr.Expression.AsString);
System.Diagnostics.Debug.WriteLine("Value: " + DocExpr.Value[True]);
System.Diagnostics.Debug.WriteLine("Formatted value: " + DocExpr.FormattedValue[True]);
// Parse formula expression:
DataSource := Report.DataSources.Item[0];
Points := DataSource.Points;
Point := Points.Item[0];
Parser := Report.CreateDocumentFormulaParser();
Parser.ClearTerms();
Parser.DocumentExpression := DocExpr As PrxDocumentExpression;
Term := Parser.AddTerm();
Parser.TermType[Term] := PrxDocumentExpressionTermType.pdettPointType;
Parser.TermPointKey[Term] := Point.Key;
Parser.TermSourceKey[Term] := 1;
Parser.TermText[Term] := "Point1";
Expr := Parser.Formula;
Parser.Parse(Expr.AsString);
System.Diagnostics.Debug.WriteLine("Number of terms: " + Parser.TermCount.ToString());
System.Diagnostics.Debug.WriteLine("Term with the 0 index: " + Parser.Term[0]);
(Report As IMetabaseObject).Save();
End Sub;
See also: