1. Pau Haro
  2. PowerBuilder
  3. Tuesday, 4 August 2020 14:30 PM UTC

Hello,

 

I'm working on a window that inherits from another that has a close on the Open event, when the condition is false I trigger this close event, but the child window keeps executing his open event and throws a null object error. 

 

Regards

Accepted Answer
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 5 August 2020 01:35 AM UTC
  2. PowerBuilder
  3. # Permalink

It's never a good idea to close a window while still "being" in the open event.

What I do:

 I have this function in my ancestor w_master window:

// of_closeFromOpenEvent()
// use this function to close any window from the Open() event:
//u2, mjl, 01/12/17: if window is maximized, you can't position outside of screen resolution, so we make it "normal" first:
if this.windowstate <> normal! then
	this.windowstate = normal!
end if
this.y = 20000 // see n_display_props.of_saveWinPos(), don't change this 20000 value without changing also the value 20000 in n_display_props!!
this.ib_closing = TRUE
this.event POST pfc_close()
return

 

From the Open event of an inherited window, I do:

if ..... then
    this.of_closeFromOpenEvent( )
    return
end if

The function closes the window, but using POST, so the window first finishes to open up. Since I don't want to see a window flash up and then immediately disappear, I move it first waaaaaay downwards: y = 20000

That way the window is out of sight when it opens up for a very short time, thus avoiding flashes.

I have somewhere a function that saves window positions, when closing windows, so I had to add an exception to NOT save the positions when Y=20000. (n_display_props.of_saveWinPos() ). If not, next time the window opens up it would be invisible.

Just an idea.

regards

 

 

Comment
  1. Pau Haro
  2. Wednesday, 5 August 2020 10:23 AM UTC
Hi Miguel,

Thanks for your answer, I did almost the same and now it's working.

Regards
  1. Helpful
  1. Miguel Leeuwe
  2. Wednesday, 5 August 2020 10:27 AM UTC
YW, glad you solved it.
  1. Helpful
There are no comments made yet.
Kevin Ridley Accepted Answer Pending Moderation
  1. Tuesday, 4 August 2020 20:26 PM UTC
  2. PowerBuilder
  3. # 1

Another thing you could do is a combination of If NOT IsNull(obj) and IsValid(obj) Then (continue) Else (don't do whatever).

Comment
  1. Olan Knight
  2. Thursday, 6 August 2020 00:29 AM UTC
Yup, that's the logic I use.
  1. Helpful
There are no comments made yet.
Andrew Barnes Accepted Answer Pending Moderation
  1. Tuesday, 4 August 2020 15:44 PM UTC
  2. PowerBuilder
  3. # 2

It sounds as through the Close() is called from the ancestor Open event, but then the descendant's Open event gets called afterward, leading to your null object refences.  Closing windows in Open events that are spawning off other events like that can cause this.

One way of handling it, would be to put an instance Boolean in your ancestor window, ib_window_closing, setting this TRUE whenever the close window logic gets invoked.  Your ancestor windows could then check the state of this variable and return immediately from their Open event when it is TRUE.

Comment
  1. Pau Haro
  2. Tuesday, 4 August 2020 15:58 PM UTC
Hi Andrew,

I tryed to do the call the Close() Function on a function but still don't work at all. I already have a boolean that is set as negative when I need to leave, but the only way to use it for me it's to put it in each of my +30 child windows that inherits from this.

Regards.
  1. Helpful
  1. John Fauss
  2. Tuesday, 4 August 2020 16:04 PM UTC
I think you're spot on, Andrew. Without implementing a means of "short-circuiting" the ancestor-to-descendant Open event chain in a manner as you've described, the descendant Open event script will be executed.
  1. Helpful
  1. Andrew Barnes
  2. Tuesday, 4 August 2020 16:28 PM UTC
That is the one downside of inheritance. If you need to make a change to the base that requires touching the descendants, it can be a lot of work.



On the other hand, maybe you could get around this using the POST keyword. So from the Ancestor's Open event, where your would close the window, use POST Close(). That should cause the window closing to occur AFTER both the ancestor's and descendant's Open events have completed.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 4 August 2020 15:23 PM UTC
  2. PowerBuilder
  3. # 3

Are you issuing the Close() PowerScript function or triggering the window's Close event? The Close() function initiates an action (the closing of the window), but the Close event executes in response to the action (the window is about to close). The triggered execution of the Close event script does not immediately force the window to close, so the Open event script continues to execute after the Close event script finishes. PB is doing exactly what your code is telling it to do.

I suggest you consider using the Close() function to initiate the closing of the window thereby causing the Close event script to execute, and immediate issue a Return command to stop execution of the Open event script after the Close() function call.

Comment
  1. Pau Haro
  2. Tuesday, 4 August 2020 15:39 PM UTC
Hi John,

I think I've explained bad, Im using the Close() function like this "Close(this)" to close the window. My code it's going through Close Event after the Close() function, but the Open event keeps gets triggered anyways.

Regards.
  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.