Order of opening

XOJO 2018r4 : Windows 10 : Desktop app
In a window with several different Controls like Buttons, ListBox, PopUpMenu, … .
In what order are the Open Event Handlers called for these controls ?
Is there a rule that determines which controls are opened first or can we define this somehow or is this random ?

Regards
Etienne

The sequence of Open events for the controls themselves is undefined. It tends to be in the order the controls were added to the window, but is not guaranteed. The Window’s Open event is defined to occur after all the control Open events, so you can count on it.

So the best practice is: The Open event for the control can affect the control itself. If you have code that needs to affect more than one control, place it in the Window Open event.

5 Likes

I’ve been working with Real Studio/Xojo for 8 years now and don’t think I’ve ever heard this put so simply, yet so effectively. If there was a “Quick Start to Xojo Programming - The Top 10 Tips to Newbies”, it would most certainly include Tim’s sage words. Can’t begin to count the number of “race condition problems” that had befuddled me before I grasped the concept that Tim so eloquently shared here.

2 Likes

Thanks for the replies.

Ok.
But when I only use code related to the propre Control it is ok ?
For example a ListBox settings like nr of columns, column width’s, …
Regards
Etienne

Did you put them in Window1.Open Ecvent and was it good for you ?

add system.debuglog currentmethodname

Markus:

Who says the order of Open event is always the same ?

The order of Open event is not really important.
It is certain that the Window.Open event is ONLY started after all the controls are ‘Opened’.
As long as I do not put any code in a Control’s open event that refers to another control I think it is alright.

@Emile_Schwarz
Yes it worked with the code in Window1.Open.

Regards
Etienne

you still need to consider that if you change the ui properties at runtime they will raise unwanted events.
somehow you need a status (enum/fsm/flag) that you know at event to skip it.
usually its better to use a method instead of coding direct in the window open event in case you will reuse is.

If you have not added them nor put code in them, who cares ?

usually something happen at change events.

Noticed that as well.

This is why I create an app.boolean named AppisStartingNow,
set to true in the first line of the app.open event,
and set to false in the last line of the app.open event.

While in the controls, I check app.AppisStartingNow, and if false, then
let’s do something.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.