tags:

views:

310

answers:

2

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.

+1  A: 

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.

Terry
The object is manipulated before it's opened, or popped up for the user to see. All I need is to replicate a window-embedded object in an array. I tried the OpenUserObject after the init call, and I get null object references.
glasnt
AFAIK you won't be able to instantiate an object non-visually, manipulate it, then display it. I'd open it to some location it won't be visible (e.g. large negative coordinates), manipulate it, then move it to the appropriate position. As for why you're getting null object references from OpenUserObject(), it's hard to tell from what you've described.
Terry
In the single-window model, the uo_ is just embedded on the datawindow, and everything just seems to work. As per my updated question description, I just need a way to dynamically replicate the creation of the object. Everything else should be already handled in the uo_.
glasnt
I'm less clear now than when we started. AFAIK, UO's can't be embedded in DataWindows, so maybe I'm misunderstanding. You can't use CREATE on visual UO's (it doesn't blow up, but it doesn't work); it has to be OpenUserObject[WithParm](). If you need it to be within something other than a window (a tabpage, for example), some people have used the SetParent Windows API call (http://msdn.microsoft.com/en-us/library/ms633541%28VS.85%29.aspx) successfully.
Terry
I have no idea how I got it working, as I mention below, what I assumed as common PB functionality was actually custombuilt structure functionality. I couldn't tell the difference until I relised that was the reason I wasn't getting any googlehits on my queries, because it was custom structuring. Thankyou for you and your cat's help, in any case :)
glasnt
A: 

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.

Hugh Brackett
A datawindow control being a seperate little yellow uo_ object guy in my pbl list?
glasnt
You place a DataWindow control on the window from the menu Insert>Control>DataWindow. It's hard to advise you without knowing more about what the original window does and what the new window should do. From the name I'd guess that uo_backorder displays information about a backordered item. Are you trying to make a window that displays multiple items that might be backordered from a window that only displays one?
Hugh Brackett
I was trying to, yes. Turns out I was doing it wrong, as I didn't realise my init functions and such weren't powerbuilder base ones :<
glasnt