Set property of Window

I’m trying to get a Window to store a boolean value in a property when it opens.
The Window frmCalendar has a public boolean property called allEvents which is going to determine the contents of a contained listbox.
I want to open frmCalendar from another Window like this -

frmCalendar.allEvents = True
frmCalendar.ShowModal

After frmCalendar opens the property allEvents is still False.

What is the best way to do this please?

Reboot and test with Xojo as the unique Open application ?

What you’re describing should work. Double check to make sure you’re not setting allEvents to false in one of the other opening events on frmCalendar (or one of its controls).

Also worth checking if ImplicitInstance is turned off for that window.

The first time you access the property for an Implicit Instance window, it actually gets created. I suspect that setting the variable that way is a little too early in the initialization sequence. Save yourself some headaches down the road and don’t use it implicitly:

Var w as new frmCalendar 
w.allEvents = true
w.showModal
1 Like

It that’s true, it’s a bug. With an auto instantiation on, a:

window.property = value

Should end as something like:

window = create_such_window()
window.initialize()
window.constructor()
window.property = value

And not something like:

window = create_such_window()
window.initialize()
window.property = value
window.constructor()

Can you share an example?

I tried to follow your information (one window calling another with only those 2 lines of code) and I get True not False.

Here is my code, you can modify it or create your own example:
CraigTest.xojo_binary_project.zip (5.5 KB)

Maybe I’m missing something.

1 Like

Also inform what Xojo version and OS. @Craig_Grech

Windows 11, Xojo 2025r1.1:

1 Like

Yes that works, although I’m using Xojo 2024 2.1 on Mac Sequoia and still using superclass Window not Desktop Window.
It has the option for the property Explicit Instance but when I open your frmCalendar it is not there.

That’s why I ask for example project. To review the code and give recommendations accordingly.

If you mean the “Implicit Instance” option is not available for a DesktopWindow class, try clicking the gear icon. The option was moved for API 2.

1 Like

OK I think I’ve found the problem. I created a method in frmCalendar to set the property value.
When I call that method from another Window the Window.open event fires first which is where I have the code to read the boolean property value (which hasn’t been set yet).
Obviously this code goes somewhere else so it fires automatically after the property has been set, but where?

You could put your “read the boolean property” code in a Timer.Action event, or put it in an external method that you delay from the Window’s Opening event with

Timer.CallLater 1, AddressOf YourMethodName

Or as a workaround, you could try setting the default value of allEvents to True in the inspector. But this might break other areas of code that operate on the assumption that it will be false at window instantiation.

That sounds like an awful hack. There are much better solutions than that.

I think that is too complex. I can just store the boolean value in an app global variable and it will work easily.
I just don’t like using global variables for local window operations.

Add your message box code to frmCalendar opening event and it will display “False”

MessageBox Self.AllEvents.ToString

I am trying to begin processing the listbox on the opening of the Window and that is why it is reading the wrong boolean value for allEvents at this point. When you assign a value to a property the Window open event fires first.