tags:

views:

1091

answers:

5

How do you return values or structures from a Popup window in Powerbuilder 9.0? The CloseWithReturn is only valid for Response windows and thus is not available. When I set a value to the Message.PowerObjectParm, the value becomes null when the Popup window closes. I need to use a Popup window so the user can click back to the caller window and scroll through rows.

Program flow: 1) Window A OpenWithParm 2) Window B is now open 3) User interacts with both windows 3) User closes Window B 4) Window B needs to pass a structure back to window A

+2  A: 

You won't be able to accomplish this the way you are thinking. Since the window you are opening from the parent is not a Response window, the two aren't explicitly linked together.

But you could accomplish this by having a public instance variable in the parent window that is of the type of your custom structure. Then from the child window before you close it, explicitly set the variable in the parent window via something like this:

w_my_parent_window_name.istr_my_structure = lstr_my_structure

This should only be done if there will only be one instance of w_my_parent_window_name instantiated.

Dougman
+3  A: 

You can get around the "one instance" of parent limitation by passing in a reference to the parent window when opening the popup, and storing the reference in an instance variable. This also ensures you're talking to the right version of w_my_parent_window_name.

Terry
I store a reference to the calling window in the structure I pass to the popup window.
nfootit
A: 

If you're using the PFC, if I remember right there was a service that you could use as well.

A: 

Message.PowerObjectParm would work for passing an object. The reason it becomes NULL when the popup is closed is because structures are auto-instantiated and auto-destroyed. They are only valid within the scope that they are declared. For example, if it's declared within a function, it will be destroyed upon completion of the function; if it's an instance variable of the popup, it will be destroyed along with the popup when it's closed.

You can copy the structure back into a variable of the same type on the parent window before closing the popup as Dougman suggests, or alternatively, you could use an object instead of a structure. E.g. just create custom object and declare public instance variables in it as you would the variables of the structure.

You of course need to explicitly create and destroy the object. An object created by the popup will remain instantiated until explicitly destroyed, even after the popup itself is destroyed.

A: 

There are always multiple ways to solve a problem. I'll propose another, even though the question is old...

When you close the popup window, you can trigger a custom event on the parent window. Well, technically, you can trigger any event on the parent window, but I'd suggest creating a custom event specifically for this so that you can pass the structure as an argument to that event.

Jason 'Bug' Fenter