I started playing with Form inheritance today and hit a bump in how I thought it would (should?) work.
What I noticed is that form variables on the parent form seem to be scoped to each individual sub-form, rather than being inherited down where each sub-form is using a reference to the parent. Is there anyway to adjust this behavior to work in a more class like inherited manner?
In my case I have a base form that defines all the needed form variables, then two sub-forms that offer two views - a ‘basic’ view with most of the data providers from the parent hidden, and an advanced view that allows the user to adjust any of the values. The way it is working now in 4.0.1 is if the user changes something in the basic view, and switches to the advanced view (or vice versa) the changes are not reflected on the other form and I can even end of with an entirely different set of values on each form.
So, if I understand correctly, you have a parent form, lets call it Form A, and a child form that inherits Form A, lets call it Form B. You have created a form variable on Form A (lets call it Global1), and placed it on Form A. Then when the user switches between Form A and Form B, Global1 may contain different values?
That is exactly what I am seeing.
In the case that you defined, what I am seeing is if you set Global1 (being a form var, not a global) on Form A and switch to Form B I see Global1 as not being set on Form B. I can then on Form B set Global1 as some value and switch back to Form A, where I will see Global1 still set to the original value. Then I am able to switch back an forth between the two forms seeing differing values.
you say it your self: “class like inherited manner”
thats exactly what servoy does. We have class inheritance, that means the inheritance is in the definition not in the instance level
if i create classes in java (forms in servoy) so i have class A that has property Z and then i have class B that extends A
then at runtime when i make an instance of A and set that property Z then when i make an instance of B and i look at property Z it wont have that value that i set at A no it has its own still the default value of Z because it is its own object.
So the same goes for forms if you extend it is the definition level. At runtime you have a Form A with its own scope and variable values and a Form B with its own scope and variable values.
Its just that they have the same definition/interface to talk to.
So form variables are tied to an instance of the form you create A.myvariable is something else then B.myvariable
Doh!
My thought process got all mixed up and I don’t know why I wasn’t thinking of each form as its own class instance, sub-classed from the parent (even though that’s what I typed). Coming off a big python project and just picking up servoy again what I was really kind of thinking of multiple inheritance with the two “sub-forms” being actually being the ancestor classes to the base.
This idea obviously fails for form layout since now I just one class/form instance.