This function creates a reference to the single FlexQuery statement or statement block embedded as the function parameter.
Such a statement block, which is called subquery, is not executed immediately.
Instead, the reference to it may be passed as a parameter of some specific functions
(e.g. iterate()
or filterElements()
).
Such functions normally iterate something and will execute the specified
statement block for each iterated item.
The embedded statement block is compiled together with the whole FlexQuery expression so as its syntax is checked during that. The block may contain any other statements, operators and function calls with no limitations.
You may also access within the block any local variables assigned
before declaring it with FlexQuery()
call.
Effectively, such variables may serve as external parameters to the block's statements
as well as receive values calculated within the block (e.g. you can increment a certain
external counter on each execution of the block).
The reference produced by the FlexQuery()
function is actually
a special object representation of the block content optimized for fast execution.
Besides passing such a reference as the parameter of some FlexQuery functions, you may
also execute the block associated with it directly using
execFlexQuery()
function.
It is also possible to compile a text string containing FlexQuery statements
dynamically using parseFlexQuery()
function and receive
a reference to the executable block the same way as if those statements were
directly written as the parameter block of FlexQuery()
function call.
Parameter:
obj
This should be a subquery statement (or a statement block) written directly in place of this parameter. When the subquery consists of multiple statements, the statement block should be enclosed in curly bracket'{}'
.Syntactically, the subquery may return any data type, however the actual returned type may depend on the further usage of that subquery.
Returns:
The reference to the compiled subquery.Note: This function never produces any errors by itself because the subquery is compiled (or checked) together with the whole expression where the function is used, so any syntax errors will be found yet during designing of the template (or raised by another function that compiles the whole expression dynamically).
See Also:
execFlexQuery(), parseFlexQuery(), BooleanQuery()
Example:
This example shows how the subquery is used to count the number
of dot '.'
characters contained in a specified string.
The string should be assigned to 'text'
variable.
For instance, this particular expression will return// assign the sample string text = "javax.swing.text.Document"; count = 0; // init the dot counter // the variable via which the current iterated // character is passed to the subquery c = ""; // the subquery to be executed // for each character in the string q = FlexQuery ({ (c == '.') ? count = count + 1; }); // iterate all characters in the string iterateChars (text, @c, q); count // return the result number of dots
3
.