Displaying the expressions

Top  Previous  Next

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 (see the "Expressions" chapter for details). 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.