Initialization order

In App.Open, I initialize and then set name of Months in several languages in an Array.

Then in the main window, I display them in a PopupMenu.

What was funny, that in that window, the popupMenu was clear (no text).

I do the same in a second window, I had a great surprise: the PopupMenu HAVE the Month names…

After some searches, checkings, it happens that both windows uses the same (exactly the same) code.

After launch, I think… What if I open the main window after the second window ? The Month Names appeared !

The construction is as follows:

  // Set the Month names
  mPrefs.gMonth_Langue = 3
  Select Case mPrefs.gMonth_Langue
  Case 0
    // Deutch
    App.gMonths() = Array("Januar", "Februar","März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember")

Etc. for some other languages…

What is your advice ?

Yes, this looks strange to me.

use System.DebugLog to follow your app flow

1 Like

In this thread about order of events, which is old but probably still applicable, Michel said he’s noticed the default window opens before App.Open. You might want to read some of those posts for ideas, but MarkusR is right…DebugLog is going to be your friend.

I do not like the idea of initializers except for when they are embedded in a constructor. Things like this can happen because you are depending on the event order, and when you do not include nil checks can stay undiscovered too under some circumstances.

A much cleaner way is to use lazy initialisers where such properties are hidden behind computed properties. Their getter checks for nil, and if so, will initialize the property before returning it. This often helps to avoid initialization delays which might happen if you have a lot of things going on inside an initializer.

In this case, I wonder why you take the effort to build month name arrays anyway. You could also retrieve the localized name from DateTime.toString. Which would fit nicely into a DateTime extension method.

1 Like

with Xojo 2021r1.1 the event order at my pc was app open and then window open

I do not use this version.

It does not works in:

And I know how to debug a project.

What I do not know is why this does not works.

A solution I already used elsewhere, but for different reasons, is to add a wMain window with icons that allows the selection of windows.
At the time the user click in a button (canvas with Icon) from that window, all other windows will be able to display the array contents correctly…

Unless proved wrong, I call that a workaround.

The Open event is the first event called when your application starts.

I just got a… “creative” idea:
I set the second window as the default window. The names of the months appeared…

Strange? You said strange? It’s strange !

is there something that make your popup empty in this one window?

No. As I wrote earlier, when I changed the default window it worked. When that window was displayed (as a second window), it worked.

I made a right-click in a file and get strange result.

So, I quit everything and reboot.

It is late, I have to go home now. I will check that tomorrow, but I suspect a foreign cause.

A DVD with Ubuntu was rejected as unreadable. After reboot on High Sierra, I was able to read its contents…

Never assume any order in events. That is described in details in the LR.

I did notice that for some reason, at least in macOS, the default windows shows up before App.Open.

However, there is a simple way to ensure that the app default windows displays after App.Open:
Set the default windows to none, and show it manually in App Open, after setting up the content.


My object string may be wrong.

But, look at what I found when I select a Window in the Navigation pane…

Because some have trouble with their eyes (me for example), I will give a hint: do you have an Obsolete entry in the Property list ?

I know why I have that.