2
votes

I m pretty new to PowerBuilder (12.5 Classic) and trying to find out if what I am doing is the right way.

I have three text controls in a PowerBuilder DataWindow named t1, t2, t3.

I am trying with the expressions so t1.Text property is set to static "Hello".

t2.text property using the expressions. So in the expression field I specify describe('t1.Text').
When I run it, it correctly displays the t2.Text as "Hello" (excluding quotes).

Now for t3 I give the expression as describe('t2.Text') which i guess is not the right thing to do because i get the result as: describe(~"t2.Text~") [inclusive of all the quotes].

I am just trying to get the Evaluated Text of a text box (here t2) and not its expression. Appreciate any help. Thanks.

2

2 Answers

2
votes

You can get the result of a field property expression for a given row in the dw_1 datawindow by using the evaluate() datawindow expression in a Describe():

string ls_expression = "t2.text"
string ls_text
ls_text = dw_1.Describe("evaluate(~"" + ls_expression + "~", " + string(row) + ")")

Edit: If you need to reuse dynamically a property into another expression in a DW, it becomes a bit tricky

  • as you cannot evaluate a property directly with eval() because the property is in the form "constant <tabulation> expression" (including double quotes),
  • you need then to either get the value directly
  • or you need to evaluate the right part of the expression with taking care of the quotes (here I add one at the beginning, but corresponding ending quote was already given by the describe).

A multi-line dw expression would be:

if(pos(describe("some_field.protect"),"~t")<1,  /*if the prop has no tab*/
    describe("some_field.protect"),             /*no expression, get it directly*/
    describe(                               /*else eval the right part*/
        "evaluate(~""
            +mid(describe("some_field.protect"), pos(describe("some_field.protect"),"~t")+1)
            +",1)"          /* 1=for row 1 */
    )
)

Some notes:

  • as you can see I call several times the describe of the expression, so it would be clearer to construct several computed fields to get in advance
    • the describe() and have only one expression to query
    • the value of the pos() of tabulation character
    • i have hardcoded the row 1 in my example (at the end of the evaluate(), you will need to use string(getrow()) or some other function to evaluate the property at the correct row (or row 0 for header IIRC)
    • beware that if you do not put that expression directly in the dw painter but set it via PBScript, you would have to expand the double quotes " or simples simple quotes ' with tilda characters depending on the kind of string used in the code
1
votes

Maybe even a simpler solution:
Make t3 a computed field with the expression describe("t2.text")