Help with Passing in Window Properties Please

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


When the form opens the Mode value is not set, just blank.

Can someone tell me what I am missing pls?


Are you able to replicate the problem in a simple demo project and upload it?

If your form, UploadData, has implicit instantiation turned ON then

'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"


  1. create the window
  2. show the window if its visible property is set to true
  3. set the Mode
    but since the window is already showing the setting is done AFTER whatever code you thought would use it

Window.Open will fire even if you have Visible = False and then show it later with ShowModal so your Mode will be Empty even during the Open event.

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


and the mode property on the window is set as you expect when the Open event is finally called

Hi Thanks for the help.

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 :frowning:

Here is what I have

In the new Constructor method

[code]// Calling the overridden superclass constructor.

Self.Mode = newMode[/code]

In the Calling buttons Action event

Dim winUD as New UploadData("ALL") winUD.ShowModal

In the Form Open event


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.

Thanks for any ideas

Switch these lines

Self.Mode = newMode

// Calling the overridden superclass constructor.

the Call to “Super.Constructor” is what eventually triggers the Open event to run

I see I missed this detail in my original reply and have edited it to correct that oversight

Got it!

That works great, thanks for your help!!

Answer marked :slight_smile: