Checking to see if Window is open

Hello all,

I have a window with Implicit Instance set to True.

How can I check to see if it is already open without opening it if it is not open?

Thanks,
Tim

Look at https://documentation.xojo.com/api/deprecated/application.html#application-window. You’ll end up doing something like this:

For i As Integer = App.WindowCount - 1 DownTo 0
  if App.Window(i) isa YourWindowName then
    // Do something
  End If
Next

Thanks Bob,
I’ll give that a try…

Tim

Where I only expect one instance of a window, I create a Shared Property, IsOpen As Boolean. In the Opened event, it sets it to True. In Closing, to False. Then it’s just a matter of checking that property, e.g., if MyWindow.IsOpen then ....

2 Likes

I use a property of the App object. In that I store the reference to the Window. If that property is Nil then the window needs opening, otherwise you can use the reference to the window. It combines the ability to check for the window being open and the ability to access the window when required. Use a shared property as they are much faster to access. Having a shared method to access the property, that can also populate it when required. Plus another to close it when required.

Public Shared Property FindWindow As FindWindowClass

Shared Function getFindWindow as FindWindowClass
   If App.FindWindow is Nil then
      App.FindWindow = New FindWindowClass
   end if 
   return App.FindWindow
End Function

Shared Function closeFindWindow
   ' Close function if you're done with the Window
   App.FindWindow.Close
   App.FindWindow = Nil
End Function

Sub AnyFunctionThatRequiresTheWindow
   App.getFindWindow.ShowModal
   If App.getFindWindow.SomeParameter = SomeValue then
      ' Do something
   end if
End Sub

Thank you everyone,
I used Kems suggestion and it works perfectly. Very easy and simple solution!

Thank you all!
Tim