Hi
Fairly new to Xojo, been using VB.NET for years. I think this has to do with when a from (Window) is created. I have a Window which I have added a Public string property.
I want to set the property value before showing the window (ShowModal) so that when the Window displays it can use the value of the Property (I have called it ‘Mode’) to determine how to display the data in the window. In this case it is to decide whether to show all data or just that which has changed. There will no doubt be other things like this I will want to do.
I am setting the property value in the Action event of a button in a container on the Main program Window thus
'This runs fine, no errors. The auto-complete shows the Mode property so I assume it is visible due to being public
UploadData.Mode = "ALL"
Then show the form
UploadData.ShowModal
When the form opens the Mode value is not set, just blank.
One way to avoid this is to create a constructor for your Window
A constructor is a means to create new instances of a window (so you could have many uploaddata windows open)
As well a constructor is called BEFORE any events on the Window are run
I would turn off ImplicitInstance for the UploadData window
Then in the UploadData Window add a new method and chnage its name to “Constructor” and you can add parameters
I would add one - newMode As String
It might look like
Sub Constructor(newMode as string)
self.mode = newMode
Seuper.Constructor // <<< EDIT ... I see I missed this when I originally wrote this
End Sub
Then your code could look like
dim w as new UploadData( "ALL")
w.ShowModal
and the mode property on the window is set as you expect when the Open event is finally called
Norman, I have tried the code you suggested, seemed to make perfect sense (Had to ensure the constructor was set Public BTW).
But Parameter still not set when the form Opens
Here is what I have
In the new Constructor method
[code]// Calling the overridden superclass constructor.
Super.Constructor
Self.Mode = newMode[/code]
In the Calling buttons Action event
Dim winUD as New UploadData("ALL")
winUD.ShowModal
In the Form Open event
ShowUploadData(Self.Mode)
The Open Event fires when ShowModal is run, I have a breakpoint on the line in the Open event, Self.Mode is empty.
This is driving me nuts. Just when I thought I was getting to grips with Xojo… This seems such a simple and common thing to do, initialise a form before showing it.