Window Instance <> Nil after Window.Close

Can you think of any reason why after I close an instance of a window (as described below) it doesn’t test as equal to Nil?

// window2 is a global property declared as an instance of window1
// window1.implicitinstance = false

// in some other window in the application I want to open an instance of window1
window2 = New window1
window2.show

// when done using window2 the user clicks on the close button
// later in the code I want to see of an instance of window1 is already open so I check
If window2 = Nil then ...

// I am sure that there are no other window2's open - but this test (= Nil) fails. And when I go further to access controls on window2 (because it fails = Nil) some of the controls on window2 ARE nil (as if they were closed).
1 Like

Hi Mark,

What you could do is use a function to figure out if the Windows that are open match a window you are looking for. If it doesn’t match then you know that window is not open.

Function CheckWindow as Boolean
  Dim n as Integer = WindowCount
  for i as integer = 0 to n-1
    if Window(i) isa <YourWindow> then
      Return True
      Exit
    Else
    end if
  next

HTH

are at any time after the window is closed are you accessing ANY attribute of the window? If so, that may reinstantiate it.

even if window is closed, the object is kept in memory until all references to it a cleared.

I have a couple of cases in my projects where events, check if control count is zero to exit right away.

Great feedback all - thanks.

If ImplicitInstance is set to true (it is by default) then referring to the Window will, in fact, instantiate it.

http://documentation.xojo.com/index.php/Window.ImplicitInstance

I recommend that you turn the ImplicitInstance to false on ALL windows. Then, use Mike’s code to see if an instance of that window is still open.

[quote=163128:@Bob Keeney]If ImplicitInstance is set to true (it is by default) then referring to the Window will, in fact, instantiate it.

I have implicitinstance = false for window1 (the master version of the window). I think I tried to reference this property in code but the compiler didn’t like it (I could be remembering that wrong). Nevertheless - wouldn’t that property be reflected in instances of the master version?