Evaluating DataWindow expressions in the Describe function
The Describe function provides a way to
evaluate DataWindow expressions outside their usual context. The Evaluate function,
which is used only within Describe, allows you
to evaluate DataWindow expressions within a script using data in
the DataWindow.
Evaluate has the following syntax:
|
1 |
<span>dwcontrol</span>.Describe ("Evaluate ( <span>'expression'</span> , <span>rownumber</span> ) " ) |
Expression is the expression you want to evaluate and rownumber
is the number of the row for which you want to evaluate the expression.
The expression can include DataWindow expression functions that
cannot be called in a script.
This example displays in the title of the DataWindow control
the current page for the current row in the DataWindow:
|
1 |
string ls_modstring, ls_rownum<br>ls_rownum = String(dw1.GetRow())<br> <br>ls_modstring = "Evaluate('Page()'," + ls_rownum +")"<br>// The resulting string, for row 99, would be:<br>// Evaluate('Page()', 99)<br> <br>Parent.Title = &<br>"Current page: "+ dw1.Describe(ls_modstring) |
This example returns the display value for the dept_id
column for row 5:
|
1 |
dw1.Describe("Evaluate('LookUpDisplay(dept_id)', 5)") |
Expressions that apply to all rows
To evaluate an expression that applies to all rows, specify
0 for the rownumber argument. This example
calculates the sum of the salary column in the current DataWindow.
It will return the expression’s result or “!” if the expression
is not valid:
|
1 |
dw1.Describe("Evaluate('Sum(Salary)', 0)") |
Evaluating user-specified expressions
In some types of applications, you might use Evaluate to get
the result of an expression the user specifies. For example, users
might specify the type of aggregation they want to see. This example
evaluates an expression specified in a SingleLineEdit. It applies
to all rows:
|
1 |
dw1.Describe("Evaluate('" + sle_expr.Text + "', 0)") |