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
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
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
Another thing you could do is a combination of If NOT IsNull(obj) and IsValid(obj) Then (continue) Else (don't do whatever).
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.
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.
Thanks for your answer, I did almost the same and now it's working.
Regards