Composing expressions
The expression evaluator is working with four data types: Strings, Integer, Float and Boolean. Binary data and memo fields are not supported in expressions. Below is a list of how database fields are converted to report data types:
|
Data type |
Field type |
|
String |
String fields, date and time fields |
|
Integer |
SmallInt fields, byte fields, integer fields |
|
Float |
Float fields, currency fields |
|
Boolean |
Boolean (logical) fields |
Report expression syntax is very much like Object Pascal. Below is a list of supported operators:
|
Operator |
Description |
|
+ |
Add |
|
- |
Subtract |
|
* |
Multiply |
|
/ |
Divide |
|
() |
Parentheses |
|
And |
Logical AND |
|
Or |
Logical OR |
|
Not |
Logical NOT |
|
= |
Equal |
|
< |
Less than |
|
> |
Greater than |
|
<= |
Less than or equal |
|
>= |
Greater than or equal |
|
<> |
Not equal |
The standard functions included are:
|
Function |
Description |
|
Date |
Return current date as a string |
|
Time |
Return current time as a string |
|
Str(Number) |
Converts the numeric argument to a string |
|
Copy(Str,s,l) |
Returns a substring of str (starting from the s-th character, returning a maximum of l characters) |
|
Int(Number) |
Returns the integer part of a number |
|
Frac(Number) |
Returns the fractional part of a number |
|
If (Expr, r1, r2) |
Returns r1 or r2 depending on the boolean expr |
|
TypeOf(Expr) |
Returns the data type of expr |
|
Sqrt(Number) |
Returns the square root of a number |
|
True |
Logical value True |
|
False |
Logical value False |
|
Sum(Expr) |
Returns the sum of expr |
|
Count |
Returns the number of entires |
|
Min(Expr) |
Returns the lowest value of expr |
|
Max(Expr) |
Returns the highest value of expr |
|
Average(Expr) |
Averages the expr |
Using database fields in expressions
Any field in any table referenced in your report can be accessed in an expression. Field names can be referenced either just by the field name itself (e.g. Name) or by the table name followed by a dot and the field name (e.g. Customers.Name). If you do not specify a table name the report engine will search for the field in all available data sets and use the first instance found.
The current version of the expression evaluator does not support field names with embedded special characters like blank, "/", dot, dollar sign and so on.
Using Strings in Expressions
Strings in expression should be put in single quotes. The following is a valid expression:
"Computers are great!"
Maximum string length is 255 characters.
Expression Examples
Below are some examples of expressions:
|
Expression |
Description |
|
1 |
Integer constant, returns 1 |
|
1.5 |
Floating point constant, returns 1.5 |
|
"Delphi" |
String constant, returns "Delphi" as a string |
|
True |
Logical constant, returns True |
|
1 + 2 |
Numeric calculation, returns 3 |
|
2 * (3 + 2.5) |
Numeric calculation, returns 11 |
|
"Delphi" + " is great" |
String calculation, returns "Delphi is great" |
|
Name |
Returns the value of the field Name if it exists |
|
Customer.Name |
Returns the value of the field Name in the Customer table |
|
Name + " " + Contact |
Adds the Name field, a blank and the Contact field |
|
AmountPaid * TaxRate / 100 |
Numeric field calculation |
|
"Printed "+ Date |
String calculation |
|
"Total amount paid is " + str(AmountPaid) |
String calculation |
|
if(AmountPaid > 5000, "Large order", "Small order") |
Returns "Large order" if AmountPaid is greater than 5000, else "Small order" |
|
if(CheckField, "X", " ") |
Prints an X if CheckField is True |
Composing expressions visually
Expressions can be typed in directly to the corresponding edit line, or you can press the button ".." to the right of the edit line to show the expression builder dialog. You can then visually design your expression with your mouse. If a used function has parameters, like "Copy" or "Sum", another copy of the dialog will be opened to define those parameters separately.