<< Click to display table of contents >> Template syntax | Variables |
See the topic about fields in templates for a general description of the syntax.
<variable> ::= [']%<variable name>['][ <variable type>][ "<format>"]
A variable name (including the starting '%' character) may be enclosed in single quotes. These single quotes are necessary, if it contains space characters.
<variable type> ::= object
<format> – see variable format strings sections below.
Variable names are case insensitive.
Variables are defined in string lists of the whole report and of report tables.
When evaluating a variable, the report generator tries to find it to the most nested table, then (if not found) in the table containing this table, and so on. Finally, it searches in the global report variables.
The report table's variables are used:
•when processing content of this table's cells while applying row generation rules;
•when processing this table's cells' data query strings.
They are not used:
•when processing data query strings belonging to this table's row generation rules,
•when processing this table's hint (tool tip).
•when processing content of this table's cells that do no belong to any row generation rule and do not have a data query.
(in these cases, you can use only variables of parent tables and global report variables).
Variables are stored in a string list. Each string in this list must have the syntax:
<variable name>=<variable value>
Before the report generation, you can create an initial set of variables for the whole report and for report tables.
You can change values of variables and add new variables:
•using $SET command inserted in a report template text
•using scripts
•in your code, in events.
When a report generation is finished, all variables that were calculated during the generation remain valid. So make sure to reset global report variables to default values before the next generation.
It is possible that a string list item has an associated object. The variable string lists own their objects, so objects are freed when the lists are cleared or destroyed, so do not free these objects yourself.
If the field type "object" is specified, this object is inserted instead of <variable value>.
The current version of Report Workshop supports only one type of objects: an image (of a class inherited from TGraphic, such as TBitmap or TPngImage).
This feature can be used to generate pictures basing on data returned for a data query in OnProcessRecord event.
Read the topic about format strings.
Variables can use format strings for strings and for images.
Variables can be used:
•to insert their value or object in text of templates;
•to insert their value in strings (such as data queries or hyperlink targets);
•as parameters of If, IfDef, IfNDef commands;
•in expressions.
Example 1
Let the report has the following item in its variables:
phone2="Work phone"
The code
{%phone2}
inserts
Work phone
Example 2
Let the report has the following item in its variables:
barcode=
and this line has an associated TBitmap object
The code
{%barcode object}
inserts this bitmap in a document.
Example 3
Let the report has the following item in its variables:
fullreport=yes
And the following data fields are defined: name, address, phone
The code
Name: {name}
{$IF %fullreport="yes"}
Address: {address}
Phone: {phone}
{$ENDIF}
generates the output like:
Name: John Smith
Address: 123 Way, Nethercity
Phone: 123456