Feedback case 55739 comments

I’m opening this topic because I think the Feedback is not where we should discuss about a topic, in this case about Windows, Visible and Implicit Instance.

I learned so far, that to control the Window that will show when your app starts you use App - Appearance - Default Window, interesting that the default window will show even if:

  • visible is False
  • implicit instance is False
  • visible and implicit instance is False
    Edit: sorry, I did something wrong, this is not the case

Other windows will not show even if Visible is True.

Changing or querying a “not shown visible window” property will act as calling the Show method.

I understand now why this happens.

I know changing the behavior could break others code, so I don’t think this behavior will change. It will be nice to update and give more information about the Visible value on the docs.

For me, as forever rookie, if App - Appearance - Default Window has control over which window will show, it would be nice to be able to set only that window to Visible True, and if it is the Window that will show, not able to set Visible to False, because really there is no effect if the selected window we change those values. In the other hand, if the apps will only open 1 window by default, then every other window not selected as the Default Window, should be Visible False and not able to turn to True. Once we start our program, we can code to show/change whatever we want.

I hope this makes sense.

If you want more control you can set DefaultWindow to none and just do everything in code.
ie: define a property for your window type, create a new instance in App.Open and then make it visible when you want.

[code]Sub Open()
Self.mMainWindow = New Window1

'do something

Self.mMainWindow.Show
End Sub

mMainWindow As Window1

[/code]

Thank you Kevin, good information.

What I expected, that if I create 2 or more windows and design all as Visible = True, that the app will start and will open all those windows. Now I know better, but still do not understand how Visible is useful at design time if I need to use code to show the windows anyway. I think it will be easier for me to know that the Window default is Visible False and then code what I want from that.

[quote=437854:@Alberto De Poo]I’m opening this topic because I think the Feedback is not where we should discuss about a topic, in this case about Windows, Visible and Implicit Instance.

I learned so far, that to control the Window that will show when your app starts you use App - Appearance - Default Window, interesting that the default window will show even if:

  • visible is False
  • implicit instance is False
  • visible and implicit instance is False
    [/quote]
    Not here it doesnt (macOS 10.12 Xojo 2019r1.1, Windows 7 Xojo 2019r1)
    Literally I just did
  • new desktop project
  • click Window1.visible to set it false
  • run
    no visible default window

Again not here

Not here but …

[quote=437854:@Alberto De Poo]
I understand now why this happens.

I know changing the behavior could break others code, so I don’t think this behavior will change. It will be nice to update and give more information about the Visible value on the docs.

For me, as forever rookie, if App - Appearance - Default Window has control over which window will show, it would be nice to be able to set only that window to Visible True, and if it is the Window that will show, not able to set Visible to False, because really there is no effect if the selected window we change those values. In the other hand, if the apps will only open 1 window by default, then every other window not selected as the Default Window, should be Visible False and not able to turn to True. Once we start our program, we can code to show/change whatever we want.

I hope this makes sense.[/quote]

Visible maybe should have been named “WillBeVisible”
But I see you’re thinking its “IsCurrentlyVisible” and that is not the case

Thank you Norman, I guess I did something wrong.

I restarted my computer, created new project, set Window1 Visible to False, run and it doesn’t show.

When I said "other windows will not show even if Visible is True, I mean, if I add more windows (Window2, Window3) they are set Visible = True, but when I run, Window1 is the only one that shows.

When I said “changing or querying a “not shown visible window” property will act as calling the Show method”, I mean:

  • new project Window1 visible true
  • add another window visible true
  • put this code Window1 open event (example, could be other code)
dim b as Boolean = Window2.Visible

when I run that, I get Window1 open and Window2 open, so I think is the same as putting Window2.Show there.

Yes, I’m thinking as “IsCurrentyVisible”, having a window visible True and not showing is not what I could expect.

As is documented for a long time:
https://documentation.xojo.com/api/deprecated/window.html#window-implicitinstance

[quote=437874:@Alberto De Poo]Thank you Norman, I guess I did something wrong.

I restarted my computer, created new project, set Window1 Visible to False, run and it doesn’t show.

When I said "other windows will not show even if Visible is True, I mean, if I add more windows (Window2, Window3) they are set Visible = True, but when I run, Window1 is the only one that shows.
[/quote]
thats expected unless your code somewhere creates new instances
the only one that is kind of “automatic” is the default window for the app
but thats just the app code creating one for you instead of you writing the code in app.open that Kevin posted

[quote=437874:@Alberto De Poo]When I said “changing or querying a “not shown visible window” property will act as calling the Show method”, I mean:

  • new project Window1 visible true
  • add another window visible true
  • put this code Window1 open event (example, could be other code)
dim b as Boolean = Window2.Visible

when I run that, I get Window1 open and Window2 open, so I think is the same as putting Window2.Show there.
[/quote]
IF you have implicit instance on its more like putting

   dim newWindow as New Window2

This has been persistently confusing for a lot of people and is one reason a lot of old time users recommend turning implicit instance OFF
If causes no end of misunderstanding about how things actually work, saves only one or two lines of code and cause no end of confusion about "Why when I do this does this window suddenly show up? " (like this thread shows)

it probably should have been named “CanBeVisible” or something thats more indicative of it being a state that it will have when its created etc … but it does serve a dual purpose since yo ucan just toggle the window to not be visible by setting visible = false

This is a problem of not understandig OOP

The “windows” you create, are just classes, code lying around. To be a “real window” you have to create an object, an instance of that class.

The “Default Window” just does this automatically, creates an instance and SHOWS it.

In the FBC, Andrea Coppini also has problems understanding the diference beetween a window being Visble and a window EXISTING.

If you have an implicit instance, when you ask for a property of the window, if the object doesnt already exists, the framework will CREATE it (the window) and then SHOW it.

If you want to see if a window is visible, you need to be shure that the window exists, there is the WindowCount and the Window functions for that.

Thank you Derk and Norman.

This is exactly what is happening:

[quote=437878:@Norman Palardy]This has been persistently confusing for a lot of people and is one reason a lot of old time users recommend turning implicit instance OFF
If causes no end of misunderstanding about how things actually work, saves only one or two lines of code and cause no end of confusion about "Why when I do this does this window suddenly show up? " (like this thread shows)[/quote]

For people not knowing Xojo, it could be better to:

  • add new windows with Visible = False
  • or better yet, only allow the Default Window to change the Visible value at design time, in fact, the Default Window set Value to True and others to False, if I change the Default Window then change those values, if I select None for Default Window, change all Visible values to False for all Windows

Alberto, you completely misunderstand how windows management works.

Imagine your app can make 20 different windows (mainWindow, preferencesWindow, dataEntryWindow, helpWindow, etc)…

Note that this is “can make”, that is not “has”. Your app doesn’t have any of the windows, it has your instructions on how to make them.

Now when you start your app do you want to see all windows? Of course not.

You set one window in the IDE as the default window. But to create that window you either use implicit instance (the app creates that window for you) or you create it yourself in the open event of your app

dim w as new mainWindow w.show

And when the app starts it will then create that mainWindow.

Note that none of the other windows exist. Your app can create them all, but NONE exists.

But to see your newly created mainWindow then it’s visible property needs to be true. If you set it to false then it is there but of course you can’t see it.

Now the visible property is true by default. Why? Because when you create a window then you usually want to see it, don’t you? Or do you want to write w.visible = true EVERY time?

Next: if you want to create a preferenceWindow you need to create one and show it:

Dim prefsWindow as preferencesWindow prefsWindow.show

If you have that code in a PushButton and you press that button in your running app, then the app will MAKE a new preferencesWindow according to your design.

Note again that the newly created preferencesWindow is only visible if it’s visible property is set to true.

Thank you Ivan and Markus, you are right, I don’t know many things but now understand a lot better than a few hours. ago.

Let’s say I want my app to open 2 windows when it starts, there is no way to do that without code. As rookie, we see that Window1, the one that does show, has Implicit Instance and Visible as True, so is not far fetched to assume that if Window2 has the same values, it will show too.

Yes App Default Window is set to Window1, but it is not clear that will only open Window1 when it start. For me (maybe lost in translation) Default is not the same as Only.

Yes it makes sense when you know what are you doing and why. I’m just trying to illustrate that the way pros think is not the same as rookies do (also because we don’t know a million things).

Having Window2 Visible True, Implicit Instance False, using this code will create and show the window:

Dim b as new Window2

if Window2 Visible False then you need this code

dim b as new Window2 b.Visible = True // or b.Show

Just to be clear, I’m not saying that letting people, at design time, change Visible False/True for new Windows is not right. I guess that saves some programmers a line or two of code (as Norman said), but for people new to Xojo, programming and design, that option is not exactly clear (and many other things in Xojo are perfectly clear for me and my low level of expertise).

I think I’m not clear enough, maybe my English is getting in the way. Sorry for that.

In the end, what I’m trying to say, I’m not the first that get confused with this and I won’t be the last. I think that adding windows with Visible False and/or adding some information to the docs, will help to make this more clear.

Thank you all for your comments.

No.

As explained above setting the visible to false by default makes no sense.

If you use implicitInstance then just refering to a window class is enough to create an instance of that class for you.

It would be less confusing if implicitInstance did not exist, and I turn it off in my apps.

But your real problem is grasping the difference between a class and an instance of a class:

It will CREATE that window IF that window is set as default window in the app object. If it is not set then you need to create one in the app.Open event.

Setting a default window in the app object is a convenience as in practically all cases that is what you want to do in a GUI app (otherwise make a console app).

Creating ALL windows when the app opens is a very unusual thing, so that would be annoying.

The way it works is exactly how it should be.

Thank you Markus, I really appreciate the time you dedicate commenting here.

One thing that is not clear is:

are you referring to:

[quote=437887:@Markus Winter]But to see your newly created mainWindow then it’s visible property needs to be true. If you set it to false then it is there but of course you can’t see it.

Now the visible property is true by default. Why? Because when you create a window then you usually want to see it, don’t you? Or do you want to write w.visible = true EVERY time?

Next: if you want to create a preferenceWindow you need to create one and show it:

Dim prefsWindow as preferencesWindow prefsWindow.show

If you have that code in a PushButton and you press that button in your running app, then the app will MAKE a new preferencesWindow according to your design.

Note again that the newly created preferencesWindow is only visible if it’s visible property is set to true.[/quote]
specifically the bold parts?

I did a little experiment:

  • new project
  • add Window2
  • set Window2 Implicit Instance off, Visible off
  • drop a generic button to Window1
  • button action code:

Dim prefwindow As New Window2 prefwindow.Show
if I understand your comment correctly, because Window2 Visible is off (False), then the prefwindow will be created and will not show?

In my test, Window2 Visible can be off or on and in both cases the Window will show. Tested on macOS 10.12.6 Xojo 2018r3 (that’s what I have in this computer, I’ll test 2019r1.1 later).

The docs about Window.Show doesn’t mention anything about Visible on/true.

Show changes the visibility - thats its purpose
try

Dim prefwindow As New Window2
prefwindow.Visible = true

Thank you Norman, I get the same as with prefwindow.Show.

Reading the docs it looks like Show forces the window to appear, and Visible = true wait until idle.

If I set Window2 Behavior Visible to On (True) at design time, and change the button’s code to:

Dim prefwindow As New Window2

it behaves the same as your code.

I guess if you are going to use Window.Show, it doesn’t matter if you set your window visible value to on or off (note: I guess Xojo removed the ON/OFF legends to go to true/false as in code, right?, I mean, if the IDE doesn’t show on/off and code reference to true/false, then we all are going to use true/false)

That is what it does and what the docs says

[quote=437897:@Alberto De Poo]In the end, what I’m trying to say, I’m not the first that get confused with this and I won’t be the last. I think that adding windows with Visible False and/or adding some information to the docs , will help to make this more clear.
[/quote]

Again, you are confusing the Visible property with the existence of the window.

If you seet visible to false and JUST CREATE a new instance WITHOUT showing it, it will exist but it will be not visible. If you SHOW a window, well, it will be created and SHOWN, (Set visible to true)

Thank you Ivan.

I wrote that, because Markus wrote: “Or do you want to write w.visible = true EVERY time?” and the code posted used w.Show, maybe I didn’t understand what he wrote.

[quote]Again, you are confusing the Visible property with the existence of the window.

If you seet visible to false and JUST CREATE a new instance WITHOUT showing it, it will exist but it will be not visible. If you SHOW a window, well, it will be created and SHOWN, (Set visible to true)[/quote]
Yes, the original confusion on case 55739 (I’m not the OP and I didn’t find about that until now because in my simple programs I don’t use more than 1 window) was about visible and implicit instance. I’m not confused anymore.

Setting Visible = False is useful when ImplicitInstance is off and you want to set up the window before you show it. Then it prevents the window from showing until you explicitly tell it to.

dim w as new Window2   // window displays here if visible = True
w.Label1.Text = "Hello World"
// do some more setup
w.Show     // window displays here if visible = False

Is not just you, most apps work that way, that is why xojo have the implicit instance, it does by default what programmers will do 99% of the time.

[quote=437978:@Alberto De Poo]Thank you Norman, I get the same as with prefwindow.Show.
[/quote]
Precisely
Show is basically “Show this” (ie/ make Visible = true)

That IS its entire purpose

Visible ? exists
for instance
I have a truck
But you cant see it
so it exists, but its not visible to you
however if I drove to your home (ie/ made visible = true) then it would both exist AND be visible

does that help ?