1
votes

I am trying to convert a VISUAL USER OBJECT that was once embedded on a window, into a DYNAMICALLY CREATED VISUAL USER OBJECT in a different window (same package).

The problem I'm getting is I can't seem to be able to create an array of these objects without getting null references or reusing the same object over and over.

At the moment, when a user needs a new array element:

long ll_count
ll_count = UpperBound(iuo_backorders[])
iuo_backorders[ll_count+1] = uo_backorder    
lb_ok = iuo_backorders[ll_count+1].init('w_backorder_popup', '', '', '', 'd_backorder_popup', sqlca, useTransObj()) 

This reuses the same uo_backorder again and again.

Using: iuo_backorders[ll_count+1] = create uo_backorder returns null object references.

The user object is contained within another window (I think), so I'm not sure if I need to move the uo_ commands out into it's own file in the PBL, or somehow change the references (new window is a child of the original, but unsure how that pertains to uo_)

All the functionality is already in the uo_, I just need to be able to work out

A) how to dynamically create a visual user object

B) how to then create an array of these objects.

2

2 Answers

1
votes

To instantiate a visual object, you need:

windowname.OpenUserObject ( userobjectvar {, x, y } )

or

windowname.OpenUserObject ( userobjectvar, userobjecttype {, x, y } )

I'd expect that you'd be able to use iuo_backorders[ll_count+1] for your userobjectvar, but if not, just use a singular user object variable and assign it to the array element after it's instantiated.

Good luck,

Terry.

0
votes

PowerBuilder is subltly trying to tell you that you're using the wrong approach. When you create visual controls at runtime via OpenUserObject, you have to manage the layout supplying the x,y coordinates for each control. Also if you want more than one of the same control you have to use the second form of OpenUserObject that Terry posted. This is fine if you want to make something like a Wizard and stack the user objects, but otherwise laying out objects in code went out with Disco. In PowerBuilder, as soon as you want to display more than one of something, especially a variable number of something, you should be reaching for a DataWindow control. In your case, you need to move the functionality that is in uo_backorder to a non-visual object, and display the data in a DataWindow. If all of the data (state) is in the DataWindow's rows, you only need one nvo for all of the rows.