Can you say more about the class hierarchy? I believe in Xojo you can have a Window subclass, which could be itself subclassed, but you can’t subclass a Window itself (since a Window functions more like a Module in terms of scope).
If you have 2 levels of subclassing going on, you would need to make sure that each one is calling Super.Constructor()
I created a class called MyWindow, derived from window
The constructor calls super.constructor, then sets any label on the window to have text of a color.
Thats basically it.
Changing the super of the problem window back to ‘Window’ made no difference.
I’m currently commenting out code blocks from all the controls in turn to see if I can find a problem control.
You say no DoEvents(), but are you using threaded code? Perhaps this code is yielding at a bad time, so that when you do this:
dim x as new MyWindow
x.show
the controls are not actually set up properly when you show the window.
You could try this instead:
dim x as new MyWindow
// do not call x.show here
Iinstead, put a Timer on MyWindow set to mode=Single with a short (250msec) period and show the window then:
MyWindow.Timer1.Action:
self.show // in a control, self means "my Window" not "me"
Also, in the past there was a difference between:
Window.Show
vs
Window.visible = true
although I think that was mainly on macOS where it mattered…
What I’d like to see is a preference that allows users to control the value of that property when they get enough experience to warrant it. The problem with outright turning it off is that it’s really bad for demos and learning, but once a developer gets to a certain point, they tend to learn why Implicit instances are such a bad thing and then have to remember to turn it off for every window they create. As a veteran developer, I’d have that default to an OFF position, but I wouldn’t want to impose that on every other user.
I should mention, it’s already ‘visible = false’ in the IDE.
I only make it visible after all the setup actions are done, but maybe even that is too soon.
Experiments continue.
Unfortunately, the Windows UI framework has never worked properly since the transition to Direct2D (for whatever reason that was). I get the impression that Xojo does some funky stuff to draw the UI which isn’t very optimised and doesn’t work as soon as you have more than a very basic interface.
Some ideas:
Try switching off the transparent flag on all controls including any container controls and their children.
If the window or controls intercept Windows WndProc messages try disabling that code.
Temporarily remove any Windows API declares that disable / prevent redrawing.
Try removing specific types of controls or make them invisible in the IDE to see if you can pinpoint what is causing the slowdown.
If these don’t help then your next step might be to contact Xojo.
How about you do a PagePanel solution where the panel you show during opening is blank or shows “Loading” and then you switch to the panel with the controls? Or use a canvas over the controls.
Add a timer (Thanks Michel)
Have the timer set the window size, and place it at -9000 left
Make the window visible (off screen)
Do all the setting up.
Move the window onscreen, using SetBounds so that all 4 properties are set in one call.
Despite all that, the whole dialog flashes briefly when it becomes visible in the main screen, which is infuriating.
But this seems to be the best I’m going to get.
The reason I asked about Dialogs is that the event loop is weird when using Dialog window styles and/or ShowModal. But if it’s a normal Document window, that shouldn’t be relevant.
keep track of the window as a global property, perhaps of the App class, e.g.
Public App.MyWindowX as MyWindow
[...]
App.MyWindowX = new MyWindow
[...]
App.MyWindowX.Close
Iterate over the Windows
For i As Integer = App.WindowCount - 1 DownTo 0
Var w As Window = App.Window(i)
If w isa MyWindow then
w.Close()
End If
Next
Windows are weird in Xojo, in that they don’t follow the general rule that “An object will be deconstructed when no more references point to it.” You can have a Window where your code doesn’t have any references to the instance, yet it stays alive nonetheless.