| ||||||||
Using interpreterFastReport has a built-in Pascal-like language interpreter. This interpreter is a powerful means of writing language-independent (Delphi or C++Builder) scripts which are used for building reports. The language used in the interpreter is a Pascal dialect with the following capabilities:
Compared to Object Pascal this language is much simplified. The following simplifications are used:
Scripts and objects Each object can have one or more code blocks. Script editing is done in the text editor window (to see the script you have to click the button at the top of the window). The script runs each time before printing an object. (The script is attached to the OnBeforePrint property of the object). Not only objects can have scripts. Bands and report pages are scriptable too. To call the band script you must open the OnBeforePrint property editor of the band (either from the Object inspector or by selecting the band and pressing Ctrl+Enter). To call the script of the report page you must open the OnBeforePrint property editor of the page (to do that you can click on an empty place on the page and call the editor from the Object inspector). Both Dialog Forms and Report Pages have scripts attached to their OnActivate property. All other object's scripts can be accessed from their Memo property or by pressing Ctrl+Enter. Code writing In scripts, you can use properties and methods of the report objects, database table fields and various constants. Also you can create variables and arrays accessible throughout the whole report. You can use procedures and functions as well. Using variables There is no need to specify the "type" of variables, they all are variant. You can use Latin letters, digits and underline symbols in variable names. Variables from scripts can be used in objects and the variables from the list of variables can be used in scripts. Script variables are stored in TfrVariables object which can be accessed through the frVariables global variable. This is an example of using an intermediate variable: begin Cust := [CustomerData.RepQuery."CustNo"]; if FinalPass then TotalSales := Arr[Cust] else TotalSales := 0; end; In this example we create a variable Cust and set it equal to the database table field value. You can also call variables defined in the data dictionary, system variables and user variables. In this case the variables' names might contain symbols that are not normally allowed by syntax rules (take Page# system variable for example). To call such variables you must use square brackets: begin a := [Page#]; end Referencing database fields You can use references to database tables in your scripts. Here is the syntax of such a reference: [FormName.TalbeName."FieldName"] The full path is used when the table and the report are located on different forms (or data module). If the components are on the same form you can address them as [TableName."FieldName"]. You can just write ["FieldName"] if you address the table on which the band you are using is based. For example if you have master data band, which is connected to Customer.db table through a data source, you can refer to the fields of this table throughout the report using just the short path. Using the full path will not slow you down - FastReport stores database field names in cache. Arrays Apart from variables you can also create arrays in your scripts. The arrays can only be one-dimensional but you can use their elements in the way that they will be treated as two-dimensional. Example of using an array: begin MyArr[0] := 'a'; MyArr[1] := 'b'; MyArr[3] := 'd'; MyArr[2] := MyArr[0] + MyArr[1] + 'c' + MyArr[3]; end; Actually the array elements' values are stored in the frVariables list in Arr_array_name_index format. I.e. in the above example the contents of frVariables will be: Arr_MyArr_0 := 'a' Arr_MyArr_1 := 'b' Arr_MyArr_2 := 'abcd' Arr_MyArr_3 := 'd' Constants You can use constants in your scripts. A simple example is using numeric, string and logical constants: begin a := 0; b := 'abcd'; c := True; d := 'That''s all!'; end; Pay attention to using single quotes inside string constants – like in Pascal, they have to be duplicated: d := 'That''s all!'. Apart from simple constants you can use such constants as color names, font type names etc. Below is the list of available constants: colors: clWhite, clBlack etc. – all standard colors + system colors; dialog box response constants: mrNone, mrOk, mrCancel; system: CRLF, Null; font style types: fsBold, fsItalic, fsUnderline; object frames: frftNone, frftRight, frftBottom, frftLeft, frftTop; text alignment in a"Text" object: frtaLeft, frtaRight, frtaCenter, frtaVertical, frtaMiddle, frtaDown; band aligning: baNone, baLeft, baRight, baCenter, baWidth, baBottom. Besides these there are constants for add-in objects, for example, csCheck for "CheckBoxObject" objects. Anything you can see in a drop-down property list box in the Object inspector can be used as a constant in scripts. Referencing objects You can reference a report's object's properties and methods in your scripts. Report objects are visual objects, control objects, bands, report pages and reports themselves. To reference an object dot notation is used, for example: Memo1.Text. To reference intrinsic properties and methods dot notation is not necessary. Properties that can be referenced are shown in the Object inspector. Some combined properties like those of Font can be referenced by using Font.Name, Font.Size etc.: begin Memo1.Font.Name := 'Courier New'; Memo1.Font.Size := 10; Memo1.Font.Color := clRed; Memo1.Font.Style := fsBold + fsItalic end; Properties such as TStrings (Memo, SQL, Items etc.) can be referenced by their index: if Memo1.Lines[1] = 'a' then Memo1.Lines[1] := 'b' Such properties can also be referenced using Add, Delete, Clear and Count: if Memo1.Lines.Count > 10 then Memo1.Lines.Delete(10) else begin Memo1.Lines.Clear; Memo1.Lines.Add('a'); end; A full list of object properties and methods can be found in the "Object properties and methods" paragraph. Make a note that referencing a non-existent method or property will not cause an error message, so be careful when writing code. Using procedures and functions Scripts can contain procedures and functions calls. A peculiar property of the interpreter, or to be more precise the parser responsible for procedure/function processing, is that procedures and functions can not have more that 3 arguments. Scripts can use both built-in procedures and external procedures, defined in the project. The list of built-in procedures and functions is in the "Built-in procedures and functions" paragraph. Note. When referencing a procedure or function there must not be a space between the procedure name and the opening bracket. Objects modification In your scripts you can make any modifications to objects, like changing size, color, contents, etc. You must remember that in a single pass report you cannot modify objects which have already been processed. That is if you try to change the contents of an object in the report title from an object lying on a report summary band there will be no changes. However, you will be able to make such a modification if you make a two-pass report. It works the same way in multi-page reports. You can reference any object by its name (names within a report are unique). But only non-processed objects can be modified. If you still need to modify a project which has already been processed you will have to make a two-pass report. List of functionsAggregate functions Aggregate functions can be used in ReportSummary, PageFooter, MasterFooter, DetailFooter, SubdetailFooter, GroupFooter and CrossFooter bands.
Sum([Part total], Band1); Sum([[Part total] + [Part price]]); Sum([Part total], Band1, 1).
String functions
Arithmetic functions
Other functions
1. Detail data 2. Detail data 3. Detail data Master data 1. Detail data 2. Detail data
Master data 1. Detail data 2. Detail data 3. Detail data Master data 4. Detail data 5. Detail data
Buttons Icon mb_Ok mb_IconError mb_OkCancel mb_IconQuestion mb_YesNo mb_IconInformation mb_YesNoCancel mb_IconWarning Procedures and functions that can be used during building a report
Prev Next === Documentation is provided by Word2Help === |
||||||||