GuiControl label +g does not work if a Class method (a Class function) reference is set directly! (Seems like a bug!)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User
Posts: 407
Joined: 26 Jun 2017, 08:12

GuiControl label +g does not work if a Class method (a Class function) reference is set directly! (Seems like a bug!)

12 Nov 2018, 20:54

Maybe just another silly bug, but it really frustrated me!

I was trying this guicontrol, +g, Bttn, % this.Test but it does not work!

Then I tried, x := this.Test, guicontrol, +g, Bttn, % x and it worked!

Really frustrating ...!

Code: Select all

_Main_Script_.Execute()
Class _Main_Script_{

	Execute()
	{

	static

	gui, add, button, vBttn, Test
	
	;________

	x := this.Test
	guicontrol, +g, Bttn,  % x		;works

	;guicontrol, +g, Bttn,  % this.Test	;does not work (why?)

	;________

	gui, show, w300 h200

	return

	guiclose:	;__________ gui close __________
	exitapp

	return
	}


	Test()		;__________ Test(function) ________
	{

	msgbox, "test function"
	return

	}

}
just me
Posts: 9456
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GuiControl label +g does not work if a Class method (a Class function) reference is set directly! (Seems like a bug!

12 Nov 2018, 21:05

GuiControl -> Functor
[v1.1.20+]: To set a function object for handling the control's events, Value must be a single variable reference, as in either of the following examples. Other expressions which return objects are currently unsupported.

Code: Select all

GuiControl +g, ControlID, %FuncObj%
GuiControl +g, ControlID, % FuncObj
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: GuiControl label +g does not work if a Class method (a Class function) reference is set directly! (Seems like a bug!

13 Nov 2018, 01:23

BTW why are you using vLabels instead of storing the hwnds?

You should probably use:
X := this.test.bind(this) instead of getting this.test directly.
Recommends AHK Studio
User
Posts: 407
Joined: 26 Jun 2017, 08:12

Re: GuiControl label +g does not work if a Class method (a Class function) reference is set directly! (Seems like a bug!

14 Nov 2018, 13:34

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
	
	}
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: OrangeCat and 315 guests