I have a question about variables and inheritance
When static variables got changed, how can I interact with that variables from inherited class?
I'm not good at English, hence I guess giving you an example would be better
Code: Select all
new A()
class A
{
static Var := 0
__New()
{
BoundA := ObjBindMethod(A, "Method_A")
Gui, Add, Button,hwndhA, Method_A
GuiControl, +g, %hA%, %BoundA%
BoundB := ObjBindMethod(B, "Method_B")
Gui, Add, Button,hwndhB, Method_B
GuiControl, +g, %hB%, %BoundB%
Gui, Show, w300
}
Method_A() {
MsgBox % "Current - " this.Var
this.Var := 1
MsgBox % "Changed - " this.Var
}
}
class B extends A
{
Method_B() {
MsgBox % "Current - " this.Var
this.Var := 2
MsgBox % "Changed - " this.Var
}
}
Var is set to 0 when script starts.
if you click 'Method_A', this.var is set to 1
if you click 'Method_B', this.var is set to 2
however, when I click 'Method_B' then 'Method_A'. MsgBox says Var is 0 although Method_B changed the value to 2
I think 'this.var' is not sharing between two classes
can you point out what's wrong?
Thanks.