Hi,
I’m trying to pass two values/parameters from one form to another, but I can’t see the values on Windows 2.
Could you please send me a simple example project with Windows 1 and Windows 2?
Thanks.
If you use values/variables which are in a module, and made global, then all windows can see them.
Similarly, they could be values which are properties of the App object.
If you want to use variables which are part of one window, in another, then you could make those variables global, and ask for them that way
Mycopy = window2.somevariable
BUT
That will eventually cause trouble if you have implicit instance turned on.
because the act of asking for that value will open a window if it doesn’t exist, and those values will be unset.
If you turn off implicit instantiation, you need to keep track of which windows you have open.
Like the global variables, you then need a global variable that is a reference to each window.
eg
TheOneAndOnlyWindow2 as Window2
…
TheOneAndOnlyWindow2 = new Window2 //(somewhere)
if TheOneAndOnlyWindow2 <> nil then
myLocalCopy = TheOneAndOnlyWindow2.somevariable
end if
Hi Jeff,
I thought about adopting the public variables solution at the Application level, but, I’m sorry to say, it’s incomprehensible that you can’t pass values from one form to another.
I’m also sorry to say that with other IDEs, you simply pass the values as parameters when calling form 2 and acquire this information in the Init (Opening) process.
You can. Add a non-private Method to the 2nd Window, which takes those values and passes them to the objects which shall receive those values. This way you can keep everything elses scope private.
You can do that, but this is new information that wasnt in your first post.
If you want to do this at the time you instantiate a new window, using ‘New’, then you need to add a public method called Constructor to the window.
eg Constructor (byRef A as integer, B as double) as boolean
A constructor can return a variable like the boolean above, or you can make the parameters byRef and amend them directly, like A and B above
It’s hard to know what a brand new window can return at that point, however.
One thing you can easily do is to pass a reference to the calling window, so that the new window can talk back to it.
eg give Window2 a property
parentwin as Window1
then your constructor can be
Method Constructor (sender as Window1)
//default constructor
parentwin = sender
end method
You start your Window2 like this:
var thenewWindow = new Window2(self)
thenewWindow.showmodal
Window2 then does what it does, gets data as it does, and at some point, sets variables on the sender window simply by doing
parentwin.somepublicvariable = someresult
there are 2 variant
MyWindow.Show
MyWindow.MyProperty = xy
MyWindow.MyMethod(xy)
var w as new MyWindow
w.MyProperty = xy
w.MyMethod(xy)
w.Show
generally if you like to access a object from outside the properties or methods must be at least public.
Hi all,
I wanted to thank everyone for the guidance.
I’ve immediately considered using public variables at the application level because I need to complete this procedure as soon as possible. Once it’s finished, I’ll do all the necessary tests with your kind guidance. Also, I don’t think the public variables solution is very good.
You’re all very kind.