Problem when calling a Method

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Problem when calling a Method

07 Apr 2014, 05:56

Hi
I have a problem.
When I call a method in a specific way "this" contains the first parameter - (logic considering "this" is just a hidden parameter):

Code: Select all

class TestClass{
TestMethod(){
	Msgbox % this
}
}

Class TestClass2{
__new(){
	this.TestSubClass:=new TestClass()
}
}

Var:="TestMethod"
Test:=new TestClass2()
Test.TestSubClass[Var].("Fail") ; I cant use Test.TestSubClass.TestMethod() in the specific context
What am I doing wrong?
Recommends AHK Studio
User avatar
uname
Posts: 23
Joined: 25 Oct 2013, 12:50

Re: Problem when calling a Method

07 Apr 2014, 07:16

Code: Select all

class TestClass{
    TestMethod(prms*) {
        Msgbox % ">" this "`n>" this.__class "`n>" prms[1] 
    }
}

Class TestClass2{
    __new(){
        this.TestSubClass := new TestClass()
    }
}

Var:="TestMethod"
Test:=new TestClass2()
Test.TestSubClass[Var].("Fail") ; I cant use Test.TestSubClass.TestMethod() in the specific context
(Test.TestSubClass)[var]("fail")


/*
•Currently x.y[z]() is treated as x["y", z](), which is not supported.
As a workaround, (x.y)[z]() evaluates x.y first, then uses the result as the target of the method call.
Note that x.y[z].() does not have this limitation since it is evaluated the same as (x.y[z]).().

*/
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Problem when calling a Method

07 Apr 2014, 07:22

HotKeyIt wrote:

Code: Select all

Test["TestSubClass"][Var]()
Doesn't do anything.
Even produces errors.
uname wrote:/*
•Currently x.y[z]() is treated as x["y", z](), which is not supported.
As a workaround, (x.y)[z]() evaluates x.y first, then uses the result as the target of the method call.
Note that x.y[z].() does not have this limitation since it is evaluated the same as (x.y[z]).().
*/
Where did you find that :shock:
Recommends AHK Studio
User avatar
uname
Posts: 23
Joined: 25 Oct 2013, 12:50

Re: Problem when calling a Method

07 Apr 2014, 07:26

Where did you find that
AutoHotkey.chm::/docs/Objects.htm
Objects
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Problem when calling a Method

07 Apr 2014, 07:29

THX
I'm so stupid. :roll:
Recommends AHK Studio
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Problem when calling a Method

07 Apr 2014, 22:15

nnnik wrote:Doesn't do anything.
Even produces errors.
It works just fine and does not produce any errors, when placed at the end of the script in your first post.

Test.TestSubClass[Var]() does not work, but that's not what HotKeyIt posted or what you quoted.
User avatar
joedf
Posts: 8953
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Problem when calling a Method

08 Apr 2014, 09:33

This is almost like the confusion i had over here: http://ahkscript.org/boards/viewtopic.php?f=5&t=2784
except... i did read the docs ;)
mixing up the different notations test.var vs test["var"]
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 195 guests