Components
Text
The "Text" object is the basis of a data presentation in FastReport. In the components palette, it looks like:
And on the report page:
Object “Text” allows to display the following text information:
- lines of text;
- expressions;
- report parameters;
- totals;
- fields from data sources;
- system variables.
Furthermore, you can combine these data in a text object.
To open the editor of the text object, you need to double-click on the object. This opens the "Expression editor":
The "Text" object can contain a plain text mixed with expressions. For example:
Today is [Date]
When printing such an object, all expressions contained in the text will be calculated. So the result may look like this:
Today is 12.09.2010
As seen, expressions are identified by square brackets. This is set in the "Brackets" property, which by default contains the string "[,]".When needed, you can use a different set of symbols, for example "<,>", or "<!,!>". In the last case, an expression in the text will be like this:
Today is <!Date!>
Apart from this, it is possible to disable all expressions. To do this, set the AllowExpressions property to false. In this case the text will be shown "as is".
Inside the square brackets, you can use any valid expression. Read more about expressions in the "Expressions" chapter. For example, an object with the following text:
2 * 2 = [2 * 2]
will be printed like this:
2 * 2 = 4
Frequent mistake - attempt to write an expression outside the square brackets. Reminding, that it is considered an expression and gets executed only that, which is located inside square brackets. For example:
2 * 2 = [2] * [2]
This text will be printed this way:
2 * 2 = 2 * 2
There may be elements inside an expression that needs own square brackets. For example, it may be a reference to a system variable. Let's look at the following example:
The next page: [[Page] + 1]
The text contains an expression [Page] + 1.
Page is a system variable which returns the number of the current report page. It is included in own brackets. These brackets must be square brackets, regardless of the "Text" object settings.
Strict speaking, we were supposed to use two pairs of square brackets when using the "Date" system variable in the examples above:
Today is [[Date]]
However FastReport allows to leave out unnecessary pair of brackets if there is only one member in an expression.
You can print the data column in the following way:
[Datasourcename.Column name]
As you can see, the square brackets are used here. The data source name and data column name are separated by the period. For example:
[Employees.FirstName]
Read more about using the data columns in the "Expressions" chapter.
There are several ways to insert a data column into the "Text" object.
In the "Text" object's editor we write the name of the data column manually. This method is the most inconvenient as it is easy to make a mistake.
In the object's editor we choose the needed data column and drag&drop it into the text:
- Drag&drop a data column from the "Data" window into the report page. In this case the "Text" object is created which contains a link to the column.
You may use some simple HTML tags in the "Text" object. By default, tags are disabled; to enable it, go "Properties" window and set the "HtmlTags" property to true. Here is a list of supported tags:
Tag | Description |
---|---|
<b>...</b> | Bold text. |
<i>...</i> | Italic text. |
<u>...</u> | Underlined text. |
<strike>...</strike> | Strikeout text. |
<sub>...</sub> | Subscript. |
<sup>...</sup> | Superscript. |
<font color=...>...</font> | Font color. The color may be either the named color (such as DarkGray), or a hexadecimal code in the #RGB format, for example #FF8030. |
The following examples demonstrate how these tags can be used.
text <b>bold text</b> <i>text in italic</i> <b><i>bold and in italic</b></i>
E = mc<sup>2</sup>
A<sub>1</sub> = B<sup>2</sup>
this is regular text, <font color=red>and this is a red one</font>
this is regular text, <font color=#FF8030>and this is an orange one</font>
This text will be displayed in the following way:
The "Text" object has the following properties which can be set in the "Properties" window:
Property | Description |
---|---|
AllowExpressions | This property allows to turn on or off the expression handling. It is on by default. |
Angle | This property indicates the text rotation, in degrees. |
AutoShrink | This property allows to shrink the font size or font width automatically to fit the text. |
AutoShrinkMinSize | This property determines the minimum size of a font, or the minimum font width ratio, if the AutoShrink property is used. |
AutoWidth | This property allows to calculate the width of object automatically. |
Brackets | This property contains a pair of symbols that designate an expression. |
BreakTo | With this property you can organize the text flow from one text object to another. For example, we have "A" and "B" text objects. The "A" object contains the long text that does not fit in the object's bounds. You can set the A.BreakTo to B, so the "B" object will display the part of text that does not fit in "A". |
Clip | This property determines whether it is necessary to clip a text outside of object's bounds. It is on by default. |
Duplicates | This property determines how the repeated values will be printed. |
FirstTabOffset | This property determines the offset of the first TAB symbol, in pixels. |
FontWidthRatio | Use this property to make the font wider or narrower. By default the property is set to 1. To make the font wider, set the property to value > 1. To make the font narrower, set the property to value between 0 and 1. |
HideValue | This property is of string type. It allows to hide values that are equal to the value of this property. |
HideZeros | This property allows to hide zero values. |
Highlight | This property allows to setup the conditional highlight. |
HorzAlign, VertAlign | These properties determine the text alignment. |
HtmlTags | Allows simple HTML tags in the object's text. |
LineHeight | This property allows to explicitly set the height of a text line. By default it is set to 0, so the default line spacing is used. |
NullValue | The text that will be printed instead of a null value. You also need to uncheck the "Convert null values" option in the "Report/Options..." menu. |
Padding | This property allows to setup the padding, in pixels. |
RightToLeft | This property indicates whether the text should be displayed in right-to-left order. |
TabWidth | This property determines the width of the TAB symbol, in pixels. |
Text | This property contains the text of the object. |
TextFill | This property determines the text fill. Use this property editor to choose between different fill types. |
Trimming | This property determines how to trim the text that does not fit inside the object's bounds. It is used only if the "WordWrap" property is set to false. |
Underlines | This property allows to display a graphical line after each text line. This property can be used only if the text is top-aligned. |
WordWrap | This property determines whether it is necessary to wrap a text by words. |
Wysiwyg | This property changes the display mode of the "Text" object to match the screen and the final printout. This mode is also used if you use the justify-align or non-standard line height. |