I'm working on a new little script which involves creating a number of GUIs inside a class. Running through some concepts and I seem to be unable to reference the class methods with a GUI g-label.
As expected - not using classes at all - this works:
Code: Select all
gui, add, text, ghello, click me
hello() {
msgbox, Hello, world!
}
gui, show
I found that this also works:
Code: Select all
class guiconstructor {
createGUI() {
gui, add, text, ghello, click me
}
}
hello() {
msgbox, Hello, world!
}
guiconstructor.createGUI()
gui, show
However, with hello() defined as a class method, I was not able to find a way to reference it with the g-label:
Code: Select all
class guiconstructor {
createGUI() {
gui, add, text, ghello, click me
}
hello() {
msgbox, Hello, world!
}
}
guiconstructor.createGUI()
gui, show
Code: Select all
createGUI() {
hello := guiconstructor.hello ; this.hello has the same behaviour
gui, add, text, g%hello%, click me
}
Code: Select all
createGUI() {
hello := func("guiconstructor.hello")
gui, add, text, g%hello%, click me
}
Using func("this.hello") instead results in runtime error "Target label does not exist, specifically g0" which I think is AHK's way of telling me that func("this.hello") returned an empty function object.
My workaround at the moment is to build my GUIs inside class methods and put the g-label routines in the same module outside of the class. This is functional but if there's a way to use the g-label routines as class methods I would prefer to do that instead.
If there's an existing script or module that implements this that would be great - I'm sure I could figure it out just looking at an example of what I'm trying to do.
Thanks!
- Pep