1. Robert Sawyer
  2. PowerBuilder
  3. Tuesday, 18 June 2024 03:42 AM UTC

First of all, thank you for your assistance to my many questions. It has really saved me a lot of time and effort.

Is there a way to convert a string to a datawindow (control)?

For example, I have an external dw with a string column that contains the name of dw's (control) - i.e.  'datawindow_1'.

I want to get the name of the datawindow (or dw control) and perform an action on the datawindow.

Want I want:

Getitemstring on external dw brings back 'datawindow_1'

Then I want to do something like datawindow_1.SetItem......but I can't because datawindow_1 is a string and not a dw.

Andreas Mykonios Accepted Answer Pending Moderation
  1. Tuesday, 18 June 2024 07:54 AM UTC
  2. PowerBuilder
  3. # 1

Hi.

John is of course correct.

But there are ways to get a reference to existing objects in a window. Any window has an array named control[] which contains all objects the window contains. So if a window has: dw_1, dw_2 and dw_3 the contents of control will be:

  • control[1] : dw_1
  • control[3] : dw_2
  • control[3] : dw_3

Now, this can help you do some things in a more dynamic mode. You can have a string, with a control name, and check to see if the control exists. If found, you may be able to do some actions to that control, depending on its type.

Here is an example of a window containing 4 datawindows, and 3 commandbuttons. Three first datawindows do have predefined data. The fourth one gets filled with the list of controls on the window (by pressing the "Get Controls" button).

I can then select any control I want from the fourth datawindow. If press the "Button Bold", it checks if the selected control is a command button. If this is the case it sets it to bold or unset it from bold. If I press the "Change DW Color" button, then if the selected control is a datawindow, it changes it's background color to red.

So, while there are limitations, there are some things you can do dynamically.

I attach a simple workspace with the above example in case you want to experiment.

Andreas.

Attachments (1)
Comment
  1. Robert Sawyer
  2. Tuesday, 18 June 2024 22:02 PM UTC
Thank you very much - very helpful - thank you for taking the time to do this.
  1. Helpful
There are no comments made yet.
Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Tuesday, 18 June 2024 06:30 AM UTC
  2. PowerBuilder
  3. # 2

Not sure I understand you correctly. In this case, "datawindow_1" would be the name of a DataWindow control? I think it should be possible to do what you want by looping through the window's control array like this:

long l
datawindow dwcontrol
for l = 1 to upperbound( w_window.control )
  if w_window.control[l].classname() = 'datawindow_1' then
    dwcontrol = w_window.control[l]
    exit
  end if
next
dwcontrol.setitem(...)
Comment
  1. Robert Sawyer
  2. Tuesday, 18 June 2024 12:34 PM UTC
I'm trying this as a start but I'm getting a null object reference here - for l = 1 to upperbound( w_window.control ) when I replace w_window with the name of my window. When I put the code behind the clicked event of a button and changed w_window with parent, it worked fine. But I want to put this script in a function. Any ideas?

thank you
  1. Helpful
  1. Benjamin Gaesslein
  2. Tuesday, 18 June 2024 12:41 PM UTC
You'll have to have some kind of reference to the window/control array for it to work. You could add a parameter to your function. Either a reference to the window itself or the control array should do the trick.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 18 June 2024 04:11 AM UTC
  2. PowerBuilder
  3. # 3

Hi, Robert -

The short answer is no.

PowerScript is a strongly-typed, compiled language. In order to be able to accomplish what you are looking for, the PowerScript statement would have to be interpreted at execution time.

Best regards, John

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.