从 Powerbuilder 9.0 中的弹出窗口返回自定义结构
如何从 Powerbuilder 9.0 中的弹出窗口返回值或结构? CloseWithReturn 仅对响应窗口有效,因此不可用。 当我为 Message.PowerObjectParm 设置一个值时,当弹出窗口关闭时该值将变为 null。 我需要使用弹出窗口,以便用户可以单击返回调用者窗口并滚动浏览行。
程序流程: 1)窗口A OpenWithParm 2) 窗口 B 现在打开 3)用户与两个窗口交互 3)用户关闭窗口B 4)窗口B需要将一个结构体传递回窗口A
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以通过在打开弹出窗口时传入对父窗口的引用并将该引用存储在实例变量中来绕过父窗口的“一个实例”限制。 这也确保您正在与 w_my_parent_window_name 的正确版本进行对话。
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.
您将无法按照您的想法完成此任务。 由于您从父窗口打开的窗口不是响应窗口,因此两者没有显式链接在一起。
但是您可以通过在父窗口中具有自定义结构类型的公共实例变量来实现此目的。 然后在关闭子窗口之前,通过如下方式在父窗口中显式设置变量:
仅当只有一个 w_my_parent_window_name 实例实例化时才应执行此操作。
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:
This should only be done if there will only be one instance of w_my_parent_window_name instantiated.
如果您正在使用 PFC,如果我没记错的话,您也可以使用一项服务。
If you're using the PFC, if I remember right there was a service that you could use as well.
Message.PowerObjectParm 可用于传递对象。 当弹出窗口关闭时它变成 NULL 的原因是因为结构是自动实例化和自动销毁的。 它们仅在声明的范围内有效。 例如,如果它是在函数内声明的,则它将在函数完成时被销毁; 如果它是弹出窗口的实例变量,则当弹出窗口关闭时,它将与弹出窗口一起被销毁。
您可以按照 Dougman 的建议,在关闭弹出窗口之前将结构复制回父窗口上相同类型的变量中,或者,您可以使用对象而不是结构。 例如,只需创建自定义对象并在其中声明公共实例变量,就像结构体的变量一样。
您当然需要显式创建和销毁该对象。 弹出窗口创建的对象将保持实例化状态,直到显式销毁为止,即使弹出窗口本身被销毁也是如此。
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.
解决问题总是有多种方法。 我会提出另一个问题,即使问题很老......
当您关闭弹出窗口时,您可以在父窗口上触发自定义事件。 好吧,从技术上讲,您可以在父窗口上触发任何事件,但我建议专门为此创建一个自定义事件,以便您可以将该结构作为参数传递给该事件。
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.
使用局部结构变量返回选定的值,只需在父窗口中使用 Message.PowerObjectParm 并在没有任何选择的情况下关闭响应窗口时验证结构变量的存在。
Use a local structure variable to return the values selected and Just use Message.PowerObjectParm in the parent window and Validate the existence of the structure variable if closed the response window without any selection.