1

My question is: How can I reference data on a datawindow via a menu on the parent window?

I am using Powerbuilder 7.

In an attempt to find a solution myself, I have used the following code:

int iNum, i

Window win
//get window
win = m_manage_truck.getParent() //get window associated with the menu

//grab all objects on window

//  Next line I get a 'NULL' value error which terminates the application
iNum = upperBound(win.control)   

What would be causing the null reference error when assigning the number of controls to iNum? (I'm assuming its a blank window object, in which case how can I find the window using the menu?)

Ultimately, I'm trying to grab data from a datawindow. Is there an simpler/better way to grab datawindow data in a function from the menu item?

Thanks

4 Answers 4

1

If you want to make it more OO then create a window ancestor... say w_a and create stub events like:

string ue_request_data(string as_requestmsg)
return ''

Remember to inherit all your windows from your window ancestor w_a and add specific code to the ue_request_data event and remove the "extend ancestor" checkbox so only the descendant code runs. Code like below but obviously you'd do something more creative.

string ls_rtnvalue
choose case as_requestmsg
case 'customer_id'
  ls_rtnvalue ='10'
case 'customer_name'
  ls_rtnvalue = 'John Doe'
case 'rowstatus'
  ls_rtnvalue = 'Modified'
case else
  ls_rtnvalue = 'Unknown message! Programming error'
end choose

return ls_rtnvalue

And finally in your menu clicked event...a dynamic call to request data as long as you inherited from w_a your code won't blow because you stubbed out the function. You could even check the classname first before making the dynamic call in case you didn't inherit all your windows from the w_a

string ls_customer_name
window lw
lw = this.ParentWindow
ls_customer_name = lw.event dynamic ue_request_data('customer_name')

OR check the classname first

string ls_customer_name
window lw
lw = this.ParentWindow
string ls_classname
if ClassName(lw) = 'w_customer_detail' then
  ls_customer_name = lw.event dynamic ue_request_data('customer_name')
end if
0

use:

win = this.parentwindow //get window associated with the menu

instead of

win = m_manage_truck.getParent() //get window associated with the menu
0

Use it like this:

w_whichwindow win
win = this.parentwindow

win.callthefunction()
0

Yeah, well that code certainly works, but is it the best method for doing what you want?

The OO purist in me has a rule: "never put business logic in a visual control", like a menu or button. You should never need to access the properties or data of a window (or its controls) inside a menu. Write a window function that accomplishes what you want, and have the menu simply invoke that window method. That makes that logic available to other events inside the window without having some crazy menu.m_whatever.triggerevent() nonsense going on.

Or better yet, create a "controller" NVO, bind it to the window in it's OPEN event, and have all the business logic for that window inside that NVO.

1
  • So, if I'm understanding you correctly, you're suggesting that I create a function on the window and referencing the function from the menu? If so, that simplifies referencing issues, but still requires access to the window from the menu. I'll certainly give it a try, thanks!
    – Rolan
    Sep 18, 2013 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.