It is possible to call to an ini class
Now the question is how to detect IsSet in the scope
I'm saving IsSet(ini) in __New with this.ini
but calling it elsewhere I still had to keep checking IsSet(ini)
According to my logic, I already checked this.ini before calling it
The subsequent IsSet(ini) is completely unnecessary
Some one-time expenses I can still ignore
But every call in OnEvent has to be checked...
Almost every time I change the median value of the gui, will check it again
Is there a way to improve this problem?
Does this expense have an impact, is it negligible?
Code: Select all
g := GuiEx()
class GuiEx extends Gui
{
__New(opt := unset, title := unset, event := unset, hasIni := true)
{
super.__New(opt?, title?, event?)
this.ini := false
if hasIni && IsSet(ini) && Type(ini) == "Class"
this.ini := true
}
__AddCtrl(name, opt := "", text := "", var := "")
{
varOpt := ""
if var && (!this.ini || (IsSet(ini) && !ini.HasProp(var)))
varOpt := " v" var
ctrl := this.Add(name, opt varOpt, text)
if this.ini && IsSet(ini) && ini.HasProp(var)
{
if name == "Checkbox"
ctrl.OnEvent("Click", (ctrl, info) => ini.ChangeKey(ctrl.Value, var) )
; ctrl.OnEvent("Click", (ctrl, info) => IsSet(ini) ? ini.ChangeKey(ctrl.Value, var) : "")
else
ctrl.OnEvent("Change", (ctrl, info) => ini.ChangeKey(ctrl.Value, var) )
; ctrl.OnEvent("Change", (ctrl, info) => IsSet(ini) ? ini.ChangeKey(ctrl.Value, var) : "")
}
return ctrl
}
}