views:

313

answers:

1

Say I have a field on a datawindow that is the value of a database column ("Insert > Column). It has conditions in which it needs to be protected (Properties>General>Protect).

I want to have the field background grey when it's protect. At the moment, the only way I can work out how to do this is to copy the protect conditional, no matter how complex, substituting the 1 (protect) and 0 (not protect) for colour values.

Is there some sort of syntax I can use in the Expression field for the column's background colour that references the protect value of the column? I tried

if (column.protect=1, Grey, White)

but it returns errorous saying it expects a TRUE/FALSE condition.

Is what I'm after impossible, or is it just a matter of getting the right syntax.

Cheers.

+4  A: 

Wow. You like complex, layered questions.

The first problem is accessing the value, which isn't done as directly as you described. As a matter of fact, you use a Describe() to get the value. The only problem with that is that it comes back as a string in the following format, with quotes around (note that we're using standard PowerScript string notation where ~t is a tab)

"<DefaultValue>~t<Expression>"

You want the expression, so you'll have to parse it out, dropping the quotes as well.

Once you've got the expression, you'll need to evaluate it for the given row. That can be done with another Describe () call, particularly:

Describe ("Evaluate('<expression>', <rownum>)")

The row number that an expression is being evaluated on can be had with the GetRow() function.

This may sound like it needs PowerScript and some interim value storage, but as long as you're willing to make redundant function calls to get a given value more than once, you can do this in an expression, something like (for an example column b):

if (Describe ("Evaluate (~"" + Mid (Describe ("b.protect"), 
Pos (Describe ("b.protect"), "~t")+1, 
Len (Describe ("b.protect")) -  Pos (Describe ("b.protect"), "~t") - 1) 
+ "~", " + String (GetRow()) + ")")='1', 
rgb(128, 128, 128), 
rgb(255,255,255))

This looks complex, but if you put the Mid() expression in a compute field so you can see the result, you'll see that simply parses out the Protect expression and puts it into the Describe (Evaluate()) syntax described above.

I have put one cheat into my code for simplicity. I used the knowledge that I only had single quotes in my Protect expression, and chose to put the Evaluate() expression string in double quotes. If I was trying to do this generically for any column, and couldn't assume an absence of double quotes in my Protect expression, I'd have use a global function to do a replace of any double quotes in the Protect expression with escaped quotes (~"), which I believe in your code would look like a triple tilde and a quote. Then again, if I had to make a global function call (note that global function calls in expressions can have a significant performance impact if there are a lot of rows), I'd just pass it the Describe ("column.protect") and GetRow() and build the entire expression in PowerScript, which would be easier to understand and maintain.

Good luck,

Terry.

Terry
Thank you *so* much Terry, this is going to be extremely useful for me :)
glasnt