1. Pau Haro
  2. PowerBuilder
  3. Friday, 17 July 2020 15:04 PM UTC

Hello,

Im trying to execute an event on a window, but the problem comes when I try to do it on a itemchanged event of a datawindow that is located into a tabpage that it's on a tab. I can't reference the window by his name, becouse I open the window like this (Open(window_parent, "window_name")) and PowerBuilder don't know that I already opened the window and throws me (Null object reference error). 

 

I need something like Parent.Parent.Parent, I don't want to use an instance variable to reference the window and I know that I can do a function on the window that triggers the event but I want to avoid that.

 

Thanks.

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Friday, 17 July 2020 15:45 PM UTC
  2. PowerBuilder
  3. # Permalink

As Chris describes, here is code from an example function (from the PFC's ancestor DW control, pfc_u_dw):

// Function of_GetParentWindow( ref window aw_parent) returns integer

PowerObject lpo_parent

lpo_parent = This.GetParent()

// Loop getting the parent of the object until it is of type window!
Do While IsValid(lpo_parent)
   If lpo_parent.TypeOf() <> window! Then
      lpo_parent = lpo_parent.GetParent()
   Else
      Exit
   End If
Loop

If IsNull(lpo_parent) Or Not IsValid(lpo_parent) Then
   SetNull(aw_parent)
   Return -1
End If

aw_parent = lpo_parent
Return 1

HTH, John

Comment
  1. Pau Haro
  2. Friday, 17 July 2020 15:48 PM UTC
Thanks for the code and for the help Jhon.



Regards.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 17 July 2020 15:29 PM UTC
  2. PowerBuilder
  3. # 1

Hi Pau;

  You need to use the GetParent() command and the Typeof() command in a loop. The GetParent will get you to the next parent up the Parent/Child chain and typeof will let you know if its a Window. If not a Window class, then continue the loop until you find the Window class at the top of the Parent/Child chain.

HTH

Regards ... Chris

Comment
  1. Pau Haro
  2. Friday, 17 July 2020 15:50 PM UTC
Thanks for the help Chris, It worked pretty nice.



Regards.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Friday, 17 July 2020 16:01 PM UTC
Hi Pau .. that's awesome! :-)
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.