开发者

Add event to dynamically declared control

This is a PowerBuilder question. I'm using PowerBuilder 12 Classic.

I have a window in which most of the controls are declared dynamically in code using OpenUserObject. When one of these controls is clicked, a panel should open in the container window. However, I'm not sure how to trigger an event from a dynamically declared control. The control type is custom (custom code in a standard vi开发者_StackOverflow中文版sual object, singleLineEdit), and I have custom code declared in the control's getfocus event. But how do I reference the container window?

I do know that I can reference the container window by name, but that's very self-limiting. Is there any other way to accomplish this?


If you don't need to pass arguments you can use parent.triggerEvent("event_name") to fire events in the window. If events or functions are defined in the window's ancestor (e.g. like PFC) you can cast parent to the ancestor type and call directly. Example using PFC:

w_master w_container

w_container = parent
w_container.of_SetUpdateObjects({this})


Use parent.dynamic from within the custom object GetFocus event. The parent keyword will reference the container of the control, and using the dynamic keyword will allow you to call any custom function or event on the container. For instance:

parent.dynamic uf_OpenPanel(ls_SomeArg)


Another technique that I like to use is add a method to your user object for setting a reference to the parent window and then store that reference in an instance variable of the user object. You can still use the dynamic keyword and make your arguments and instance variable generic of type 'window'

This technique is useful if you have complex custom visual controls with more than one level of visual controls (e.g. tab--> datawindow ) and the parent might not necessarily be the parent window and you'd need to bubble the events backwards. It isn't necessarily better than the prior example but something useful to add to your arsenal of programming techniques.

Immediately after you CREATE your custom object then make a function call like:

window lw

lw = this iuo_customcontrol.uf_setparent(lw)

In custom control, add instance variable and function/event: protected: window iw_parentwindow

New function: uf_setparent(window as_window): iw_parentwindow = as_window

Then in any control of your custom object use your instance variable to make a dynamic function call to your parent window

iw_parentwindow.EVENT dynamic ue_retrieve() or iw_parentwindow.dynamic wf_retrieve()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜