In redesigning a control I realized that the window constructor is called after the control constructor. Is this the correct behavior? The LR only says:
I know that a control’s open event is called prior to the window open event, but I find it strange, that a control’s constructor should be called before the one of the window.
I recall a discussion (not related to this question) which included a discussion about the order of the steps when a window is created.
Framework resets public control properties AFTER constructor
Rick Araujo wrote at some place during this conversation, that he believed the order to be along this:
Allocate resources - Window
Constructor - Window
Allocate resources - Component
Constructor - Component
And Thom McGrath wrote, that something like this happens in a window:
Function Constructor ()
Self.PushButton1 = New PushButton
AddHandler PushButton1.Action, AddressOf PushButton1_Action
In both cases the window constructor is believed to be called prior to the control constructors.
Window constructor is definitely called before the control constructors. It is the window constructor (actually the Super.Constructor in the window constructor) that initates the creation of the controls. Where are you seeing otherwise?
That’s the code of a small test I wrote. Tested in RB 2012 R 1 and Xojo 2013 R 4.1.
Numbers after BREAK indicate the order of the Break statements being called:
[code]Class PushButtonSubclass // Inherits PushButton
BREAK // 1.
Class Window1 // Inherits Window and has an instance of PushButtonSubclass on it
BREAK // 2.
BREAK // 3.
It doesn’t matter if ImplicitInstance is True or False.
By golly, you’re right. I must have been thinking Open events. I suppose it kind of makes sense that the controls would have to be constructed before the window, since the window constructor calls their open events. Does it matter? Or is this a theoretical question?
Conventional wisdom has been to not count on the order of events except that app.Open should fire before any other events, and the controls of a window will fire their Open event before the window’s Open event.