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 -
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).
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
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.
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.
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.