Evaluating conditional DataWindow expressions with current data
Querying a property for a column
Values for column properties normally apply to all the rows
in the column. For example, if you set the Protect property to “1” for
the Emp_Id column, the user will be unable to modify Emp_Id
for any of the rows. If you query the property value for this column
at runtime, it will return “1”.
When the column has a conditional expression
Instead of a constant, you can assign a conditional expression
to some column properties. Such properties are set on a row-by-row
basis at runtime.
For example, you might wish to allow users to enter an employee
id for new rows but protect this value for existing rows. The conditional
expression for this column’s Protect property would be:
|
1 |
If(IsRowNew(), 0, 1) |
When you query the Protect property at runtime, the result
in this case would be the actual expression (preceded by a default
value and a tab character and enclosed in quotes) instead of the
property value. The value for the Protect property would be:
|
1 |
"0 <tab> If(IsRowNew(), 0, 1)" |
Getting a property value for a particular row
To obtain the actual value of the Protect property for a particular
row, you need to strip off the default value and the tab and evaluate
the returned expression for the desired row. After stripping off
the extra information, you can construct an expression for Describe that
uses the Evaluate function.
This example checks whether the value of the Protect property
for emp_id is a constant or a conditional expression. If
it is a conditional expression, the script builds a string for the Describe function
that uses Evaluate to get the value for of Protect
for the current row:
|
1 |
string ls_protect, ls_eval<br>long ll_row<br> <br>ll_row = dw1.GetRow()<br>ls_protect = dw1.Object.id.Protect<br> <br>IF NOT IsNumber(ls_protect) THEN <br> <br> // Get the expression following the tab (~t) <br> ls_protect = Right(ls_protect, & <br> Len(ls_protect) - Pos(ls_protect, "~t")) <br> <br> |
|
1 |
// Build string for Describe. Include a leading <br> // quote to match the trailing quote that remains<br> ls_eval = "Evaluate(~"" + ls_protect + ", " & <br> + String(ll_row) + ")" <br> <br> ls_protect = dw1.Describe(ls_eval)<br> <br>END IF<br> <br>// Display result<br>st_result.Text = ls_protect |