How to create an array of User Objects in Powerbuilder?
- by TomatoSandwich
The application has many different windows. One is a single 'row' window, which relates to a single row of data in a table, say 'Order'. Another is a 'multiple row' datawindow, where each row in the datawindow relates to a row in 'Order', used for spreadsheet-like data entry
Functionality extentions have create a detail table, say 'Suppliers', where an order may require multiple suppliers to fill the order. Normally, suppliers are not required, because they are already in the warehouse (0), or there may need to be an order to a supplier to complete an order (1), or multiple suppliers may need to be contacted (more than one).
As a single order is entered, once the items are entered, a User Object is populated depending on the status of the items in the warehouse. If required, this creates a 1-to-many relationship between the order and the "backorder". In the PB side, there is a single object uo_backorder which is created on the window, and is referenced by the window depending on the command (button popup, save, etc)
I have been tasked to create the 'backorder' functionality on the spreadsheet-line window. Previously the default options for backorders were used when orders were created from the multiple-row window. A workaround already exists where unconfirmed orders could be opened in the single-row window, and the backorder information manipulated there. However, the userbase wants this functionality on the one window.
Since the functionality of uo_backorder already exists, I assumed I could just copy the code from the single-order window, but create an array of uo_backorder objects to cope with multiple rows.
I tried the following:
forward
..
type uo_backorder from popupdwpb within w_order_conv
end type
end forward
global type w_order_conv from singleform
..
uo_backorder uo_backorder
end type
type variables
..
uo_backorder iuo_backorders[]
end variables
..
public function boolean iuo_backorders();
..
long ll_count
ll_count = UpperBound(iuo_backorders[])
iuo_backorders[ll_count+1] = uo_backorder //THIS ISN'T RIGHT
lb_ok = iuo_backorders[ll_count+1].init('w_backorder_popup', '', '', '', 'd_backorder_popup', sqlca, useTransObj())
return lb_ok
end function
..
<utility functions>
..
type uo_backorder from popupdwpb within w_order_conv
integer x = 28
integer y = 28
integer width ...
end type
on uo_backorder.destroy
call popupdwpb::destroy
end on
The issue I face now is that the code commented "THIS ISN'T RIGHT" isn't correct. It is associating the visual object placed on the face of the main window to each array cell, so anytime I reference the array cell object it's actually referencing the one original object, not the new instances that I (thought) I was creating.
If I change the code iuo_backorders[ll_count+1] = create uo_backorder the code doesn't run, saying that it failed to initalize the popup window. I think this is related to the class being called the same thing as the instance.
What I want to end up with is an array of uo_backorder objects that I can associate to each row of my datawindow (first row = first cell, etc).
I think the issue lays in the fact it's a visual object, and I can't seem to get the window to run without adding a dummy object on the face of the window (functionality from the original single-row window). Since it's a VISUAL object, does the object indeed need to be embedded on the windowface for the window to know what object I'm talking about? If so, how does one create multiple windowface objects (one to many, depending on when a row is added)?
Don't hesitate to inquire regarding any more information this issue may require from myself. I have no idea what is 'standard' or 'default' in PB, or what is custom and needs more explaining.