Passing data between windows

I am in WINDOW1, which contains some data in some properties. When the user clicks a button, I open a new window, and I want the data from the originating window (WINDOW1) properties to draw a chart. The problem is with the code:

Dim w as new wndChart

This code fires the open event of the new window, and since I am drawing the chart when the window opens, I cannot assign the calling window property in the newly opened window.

What is the preferred method for this? There will be multiple instances of both windows.

One way…

You could create an init method in your wndChart window and pass your properties as parameters. Move the code from the open event to the init method.

Dim w as new wndChart


or create a constructor method and do it all at once…

Dim w as new wndChart(a,b,c)

Create a property mWindow1 and a constructor method in Window2:

Sub Constructor(w As Window1) Self.mWindow1 = w End

Then you can open the second window like this in the button’s Action event of Window1:

Dim w2 As New Window2(Self)

And in the Open event of Window2 you then can use mWindow1.

Excellent. Thank you very much!

[quote=290771:@Bryan Dodson]Dim w as new wndChart

You need to keep a reference to w.

The simplest way to go is to keep a reference as a variable in a module, or in app, such as

w as wndChart

Then instead of using Dim, do

w = new wndChart

Afterward, you are able to access any variable or control on the w window.