Zeos Component Library:: Expression Reference Guide
Zeos Component Library:: Expression Reference Guide
Zeos Component Library:: Expression Reference Guide
Guy Fink
Chapter 1
Expressions
The expression parser in Zeos follows the normal Pascal syntax for expressions with some
limitations due to the purpose of the expression and the fact that it is interpreted.
1 Data types
The following data types are available and map to the indicated internal data types:
Boolean : 0 is interpreted as FALSE any other value as TRUE
Integer : 64-bit integer
Float : 10-byte floating point aka EXTENDED
String : standard ANSI-String
UnicodeString : standard WIDE-String
DateTime : TDateTime
Pointer : Pointer
Interface : IZInterface
Internally the expression-parser uses a ligthweight variant type for any variable. Type conversions
are done if they make sense.
2 Operators
The expression parser knows the following operators :
2.1 Arithmetic operators
Arithmetic operators can be used with the following types :
+ Additon Integer, Float, String, DateTime
- Subtraction Integer, Float
* Multiplication Integer, Float
/ Divison Integer, Float
% Modulo Integer
^ Power Integer, Float
2.2 Boolean/Integer operators
The following operators can only be used with boolean or integer types.
AND Logical AND
OR Logical OR
XOR Logical XOR
NOT Logical NOT
For integer types, a bitwise operation is performed.
2.3 Comparison operators
The comparison operators return a boolean value:
= equal
<>, != not equal
> greater than
< less than
>= greater than or equal
<= less than or equal
IS test if a variable is NULL
The IS-Operator can only be used with the special constant NULL as rigth-side operand. NOT
may be used as modificator.
Example :
x IS NULL // returns TRUE if variable x is unassigned
x IS NOT NULL // returns TRUE if variable x is assigned
+ Concatenates strings
LIKE special comparison operator for strings
The LIKE-Operator is a special string comparison operator. It takes a regular expression as rigth-
side operand. NOT may be used as modificator.
The LIKE-Operator calls the pattern matching function IsMatch.
Examples from the source file :
IsMatch allows unix grep-like pattern comparisons, for instance:
procedure ClearValues;
procedure Clear;
For the filterexpression object this list is filled with the fields of the corresponding dataset.
To create Variants you can use the following functions from ZVariant.
function EncodeNull : TZVariant;
function EncodeBoolean(const Value: Boolean): TZVariant;
function EncodeInteger(const Value: Int64): TZVariant;
function EncodeFloat(const Value: Extended): TZVariant;
function EncodeString(const Value: String): TZVariant;
function EncodeUnicodeString(const Value: WideString): TZVariant;
function EncodeDateTime(const Value: TDateTime): TZVariant;
function EncodePointer(const Value: Pointer): TZVariant;
function EncodeInterface(const Value: IZInterface): TZVariant;
To convert a Variant back to a Pascal-type use one of the Variantmanagers.
Variables are used in an expression just as they are in Pascal. Keep in mind that there is no
assignement operator.
4 The Variantmanager
The Variantmanager is used to convert the type of variants. 2 different versions are implemented
in ZVariant. DefVariantManager with strict conversion rules, and SoftVariantManager with very
soft conversion rules.
TExpression holds an own VariantManager (property VariantManager) which by default uses the
soft conversion rules.
5 Functions
As a first overview the functions are described by their Pascal-like declaration. They behave like
their Pascal-counterparts, exceptions are documented.
Some of the longname functions have short (rather cryptographic) aliases.
// Trigonometric functions
FUNCTION COS(x : FLOAT):FLOAT;
FUNCTION SIN(x : FLOAT):FLOAT;
FUNCTION TAN(x : FLOAT):FLOAT;
FUNCTION COT(x : FLOAT):FLOAT;
// Rounding functions
FUNCTION CEIL(x : FLOAT):INTEGER; // rounds toward positive infinity
FUNCTION FLOOR(x : FLOAT):INTEGER; // rounds toward negative infinity
FUNCTION ROUND(x : FLOAT):INTEGER;
FUNCTION TRUNC(x : FLOAT):INTEGER;
// Capitalize uppercases the first char of every word in the string. A word
// always starts after one of the chars in DELIM.
// The DELIM parameter is optional and defaults to the shown string.
FUNCTION CAPITALIZE(S : STRING; DELIM : STRING = #0..#32+',.;/\:''"`') : STRING;
alias
FUNCTION CAP(S : STRING; DELIM : STRING = #0..#32+',.;/\:''"`') : STRING;
FUNCTION TRIM(S : STRING) : STRING; //remove all leading and trailing blanks
FUNCTION LTRIM(S : STRING) : STRING; //remove all leading blanks
FUNCTION RTRIM(S : STRING) : STRING; //remove all trailing blanks
// Soundex calculates the soundex key for a given string. This key can be
// used for phonetic comparison. Soundex works only well for english names.
// The LEN-parameter is optional.
FUNCTION SOUNDEX(S : STRING; LEN : INTEGER = 4) : STRING;
FUNCTION DATE() : DATETIME; //returns the actual date, the time part is 0
FUNCTION TIME() : DATETIME; //returns the actual time, the date part is 0
FUNCTION NOW() : DATETIME; //returns the actual date and time
// Encode a Date
FUNCTION ENCODEDATE( YEAR : INTEGER=0;
MONTH : INTEGER=1;
DAY : INTEGER=1) : DATETIME; // alias ENCD(..)
// The same for the Timepart
FUNCTION ENCODETIME( HOUR : INTEGER=0;
MIN : INTEGER=0;
SEC : INTEGER=0;
MSEC : INTEGER=0) : DATETIME; // alias ENCT(..)