Well, I think that
ObjBindMethod(this, "Test") is more practical then
this.test.bind(this), though I don't know if there is any disadvantage on using the former instead using the latter!
Code: Select all
_Main_Script_.Gui() ;execute "Gui()" function from "_Main_Script_" class\object
return
F11:: ;_______________ F11 hotkey _________________
msgbox, % ""
. _Main_Script_.gui("x") "`r`n`r`n" ;get "Static.x" value from "Gui()" function that belongs to "_Main_Script_" class\object
. _Main_Script_.gui("ButtonTestId") "`r`n`r`n" ;get "Static.ButtonTestId" value from "Gui()" function that belongs to "_Main_Script_" class\object
_Main_Script_.Test() ;execute "Test()" function from "_Main_Script_" class\object
return
Class _Main_Script_{ ;_________________ _Main_Script_(Class/Object) __________________
Gui(_Options_ := "") ;____________ Gui(Function) _____________
{
static Static := []
if (_Options_ != "") ;returns "keys" values from "Static" Object to the caller _ Example: _Main_Script_.gui("x") or this.gui("x")
return, Static[_Options_]
Static.x := "xxx gui xxx"
gui, add, button, +HwndTempControlId, Test (or Press F11 or F12)
Static.ButtonTestId := TempControlId
;_____
TempFuncRef := ObjBindMethod(this, "Test") ;the reference of "Test()" function from "_Main_Script_" class\object is stored in "TempFuncRef" variable
GuiControl, +g, % Static.ButtonTestId, % TempFuncRef ;Unfortunately, % ObjBindMethod(this, "Test") , can't be used here directly!
Hotkey, F12, % TempFuncRef ;now works by using ObjBindMethod(this, "Test") instead "_Main_Script_.Test" ! (Unfortunately, % ObjBindMethod(this, "Test") , can't be used here directly!)
;_____
gui, show, w300 h200
return
guiclose: ;__________ gui close __________
exitapp
return
}
Test() ;_________ Test(Function) ___________
{
gui, destroy
x := "xxx Test xxx"
msgbox, % ""
. "Test" "`r`n`"
. "`r`n"
. "x from Test() = " x "`r`n"
. "`r`n"
. "Static.x from Gui() = " this.Gui("x") "`r`n" ;get "Static.x" value from "Gui()" function that belongs to "_Main_Script_" class\object
. "`r`n"
. "Static.ButtonTestId from Gui() = " this.Gui("ButtonTestId") "`r`n" ;get "Static.ButtonTestId" value from "Gui()" function that belongs to "_Main_Script_" class\object
. "`r`n"
. "press ok to continue!"
this.Gui() ;execute "Gui()" function from "_Main_Script_" class\object
}
}