Floating Window will not show after Main Document Window is minimised

  1. ‹ Older
  2. 4 months ago

    Steve K

    Apr 14 Melbourne, Australia

    Well, that is getting somewhere.

    The only issue I have now is I get an error in the Deactivate Event of the App.

    App.Deactivate
    Static reference to instance method: call this on an instance of class Window.
    WindowGraphHelp.Hide

  3. Jeff T

    Apr 14 Midlands of England, Europe

    uncheck “implicit instance”

    Means that there is no longer a window that can be referred to directly as

    WindowGraphHelp

    Add a property to your app called

    theWindowGraphHelp   as  WindowGraphHelp

    Initialise it somewhere like:

    if theWindowGraphHelp = nil then theWindowGraphHelp = new WindowGraphHelp

    refer to it through your app with

    theWindowGraphHelp instead of WindowGraphHelp

    including in the deactivate event:

    if theWindowGraphHelp <> nil then  WindowGraphHelp.Hide
  4. Steve K

    Apr 14 Melbourne, Australia

    Thanks Jeff. What do you mean by "Initialise it somewhere" ?

  5. Jeff T

    Apr 14 Midlands of England, Europe

    "Initialise it somewhere" ?

    If you know you will ALWAYS want such a window, do this once only in the App.open event

    theWindowGraphHelp = new WindowGraphHelp

    If you don't know for certain, then whenever you were going to use such a window, put the initialisation code just before you use it, wherever you use it.

    eg where you had

    WindowGraphHelp.someproperty = "ABC"

    code defensively by making sure you do have a window

    if theWindowGraphHelp = nil then theWindowGraphHelp = new WindowGraphHelp
    theWindowGraphHelp.someproperty = "ABC"

    Getting clever, you could make theWindowGraphHelp into a computed property where the GET initialises the variable if it doesnt exist, transparently. That's probably for another day.

  6. Steve K

    Apr 14 Melbourne, Australia

    @Jeff T . . .That's probably for another day.

    You're not wrong there. :)

    I still can't get this working. As suggested I've added the property to the App:

    theWindowGraphHelp As WindowGraphHelp

    Fine so far.

    I've included in the App.Open event:

    theWindowGraphHelp = New WindowGraphHelp

    Which I guess as expected shows an instance of the WindowGraphHelp at application start up - which is not really what I want.

    So when you say:

    If you know you will ALWAYS want such a window, do this once only in the App.open event

    do you mean if I ALWAYS want the said window shown at all times? I don't. It should only happen when I press a button to show it.

    I've been experimenting for the last 20mins or so and I seem to be going around in circles.

    Also where you say:

    theWindowGraphHelp.someproperty = "ABC"

    Does this mean something like theWindowGraphHelp.Visible = True/False which I don't have in my code. I thought I only had to deal with .Show or .Hide

  7. Steve K

    Apr 14 Melbourne, Australia

    I'll try to clarify exactly where I'm at.

    Creating the property, all fine.
    The code in the Open event of the App. all fine.

    Except that the window opens when the app starts. Ok, so I close it. Then how do I open it again?

    If I use code in the button to open the window again I get errors:

    theWindowGraphHelp.Show (This item doesn't exist)
    WindowGraphHelp.Visible = True (This item doesn't exist)
    WindowGraphHelp.Show (Static reference to blah bla bla...)

    So, now I can't work out how to show the window again regardless of any other requirements minimising the window and the deactivate method.

  8. Jeff T

    Apr 14 Midlands of England, Europe
    Edited 4 months ago

    OK.
    You dont always want the window to be shown.
    Dont do theWindowGraphHelp = new WindowGraphHelp in app.open.

    Later , you do this:

    theWindowGraphHelp.Show

    Do this instead:

    if theWindowGraphHelp = nil then theWindowGraphHelp = new WindowGraphHelp
    theWindowGraphHelp.Show
  9. Steve K

    Apr 14 Melbourne, Australia

    What the heck have I done!

    No, this doesn't work either. I'd like to sort this out before one of us dies from frustration (ie. fawlty towers) :)

    I think there is something I have missed that you have assumed - maybe.

  10. Steve K

    Apr 14 Melbourne, Australia
    Edited 4 months ago

    I get "this item doesn't exist "theWindowGraphHelp".

  11. Ulrich B

    Apr 14 Pre-Release Testers, Xojo Pro Answer Europe (Germany, Berlin) · xo...
    Edited 4 months ago

    Another proposal:
    The problem with a window as an app property is that if you try to close it and none existed yet, it will be created and shown once you address it in the manner above.
    Instead you could do this:

    In your WindowGraphHelp open method:

    For q As Integer = 0 To WindowCount-1
      Dim w As Window = Window(q)
      If w IsA WindowGraphHelp Then 
        w.Show
        Return
      End If
    Next
    Dim w As New WindowGraphHelp

    And in your close method:

    For q As Integer = 0 To WindowCount-1
      Dim w As Window = Window(q)
      If w IsA WindowGraphHelp Then 
        w.Close
        Return
      End If
    Next

    (Edited to use your naming scheme)

  12. Steve K

    Apr 14 Melbourne, Australia

    Thanks Ulrich, I'll try that method.

    One thing I have noticed is that with the code in the open event, as Jeff suggested, the window that does open on application start is NOT a floating window, ie. selecting the main underlying window then comes to the front.

    I've checked by testing my previous working version and it does behave "normally" except for when the floating window is closed, the app minimised, then maximsied and the floating window cannot be opened again.

    Maybe there is an issue with 2016R3 and Win7. I would have thought though, that others would have come across this before because what I want to do seems very straightforward.

    I'll test and report back shortly.

  13. Steve K

    Apr 14 Melbourne, Australia

    Unfortunately that code straight up gives an error:

    Can't find a type with this name
    If w IsA FloatWindow Then

    Maybe something to do with 2016R3 Win7 ???

  14. Ulrich B

    Apr 14 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    No, sorry. I did not use your naming scheme first. Copy the edited code (or replace floatWindow by WindowGraphHelp)

  15. Steve K

    Apr 14 Melbourne, Australia

    Sorry Ulrich, that was my fault. Thanks for editing the code.

    Well, I don't get any errors anymore . . . and it works well . . . but it behaves similar like my original code (but not the same).

    I've spent the last 15mins trying to trace and track down when and how the issue comes about. A "built version" does similar but not exactly the same as what occurs in the IDE debug mode.

    The only other thing I can think of is in the App.Deactivate event where I still have the code:

    WindowGraphHelp.Hide

    Maybe the code needs chaning there?

  16. Ulrich B

    Apr 14 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    @SteveKelepouris Maybe the code needs chaning there?

    I think so. I would replicate the close method, but this time with hide instead of close.

  17. Jeff T

    Apr 14 Midlands of England, Europe
    Edited 4 months ago

    I get "this item doesn't exist "theWindowGraphHelp".

    OK.
    My fault.. I said make theWindowGraphHelp a property of the app.

    That might have been better in a global module, as a global variable.

    If it is currently a property of the app, then you need to prefix with app.

    Like this:

    if app.theWindowGraphHelp = nil then  app.theWindowGraphHelp = new WindowGraphHelp
    app.theWindowGraphHelp.Show
  18. Ulrich B

    Apr 14 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    @Jeff T If it is currently a property of the app, then you need to prefix with app.

    Don’t mix both ways. I personally would recommend my approach because you will not create a window if you try to close it and it did not exist before.

  19. Steve K

    Apr 14 Melbourne, Australia

    Guys, thank you all. This now works perfectly!!! :) As per Ulrich's methods... Yippeeee . . . . . . . . .

    Random tests, opening the floating window, closing, minimising the main, maximising, opening again, etc. etc. - no problem and it all works as expected.

    So thanks you Greg, Jeff and Ulrich for your time and effort.

    I have to say that I'm surprised that this sort of thing, being a child of the main window, doesn't just work anyway without the extra code. Surely others have been frustrated by this. But I can tell you that I'm damm well glad to have a solution and will remember (copy the same code :)) for future applications. It's an important piece of knowledge.

    I'm at the point in my app that I'll be releasing a beta version shortly, and although it will be for free, there was no way I could release it with that bug.

    So Ulrich, If you could summarise, or maybe I could? - not sure how to go about this, but the solution as in "this answers my question" needs to be dealt with.

  20. Ulrich B

    Apr 14 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    Really glad to read that, Steve!
    I don’t mind if you summarize it. The main point is simply that instantiating a window as a property will always create one which is unnecessary if you just want to make sure it is closed.
    The only case where I would recommend such an approach is when you have something like a MainWindow that will always exist as long as the app is running. (But that’s my personal preference and you can use different approaches. In many cases they will create the necessity for even more code to cope with different situations.)

    One might have the idea that enumerating the windows could cause some slowdown. I can assure you you will almost not be able to measure the suspected overhead.

  21. Steve K

    Apr 14 Melbourne, Australia
    Edited 4 months ago

    Well Ulrich, I have to admit that I don't understand why it works. I'm just happy that it does.

    If you've ever seen the movie The Matrix (I think the 2nd one - reloaded) then there is a scene where Neo and Councillor Hamman are on a high balcony (in Zion) overlooking the water and air purification systems/machines. Councillor Hamman says that he doesn't really know what the machines do, but makes the point that he understands the importance of why they are there.

    I'm not saying that that is my approach to programming, but in certain circumstances , with some parts, I don't know or have the brains or time to work out the intricate bits

    Thank you so much for sticking with my problem and solving it.

    Cheers, +1000 points. :)

or Sign Up to reply!