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:

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:

"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:

string ls_protect, ls_eval
long ll_row

ll_row = dw1.GetRow()
ls_protect = dw1.Object.id.Protect

IF NOT IsNumber(ls_protect) THEN   

      // Get the expression following the tab (~t)   
      ls_protect = Right(ls_protect, &      
         Len(ls_protect) - Pos(ls_protect, "~t"))   

      // Build string for Describe. Include a leading   
      // quote to match the trailing quote that remains
         ls_eval = "Evaluate(~"" + ls_protect + ", " &      
         + String(ll_row) + ")"   

      ls_protect = dw1.Describe(ls_eval)


// Display result
st_result.Text = ls_protect