Page 1 of 1

Problem when calling a Method

Posted: 07 Apr 2014, 05:56
by nnnik
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?

Re: Problem when calling a Method

Posted: 07 Apr 2014, 07:09
by HotKeyIt

Code: Select all

Test["TestSubClass"][Var]()

Re: Problem when calling a Method

Posted: 07 Apr 2014, 07:16
by uname

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]).().

*/

Re: Problem when calling a Method

Posted: 07 Apr 2014, 07:22
by nnnik
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:

Re: Problem when calling a Method

Posted: 07 Apr 2014, 07:26
by uname
Where did you find that
AutoHotkey.chm::/docs/Objects.htm
Objects

Re: Problem when calling a Method

Posted: 07 Apr 2014, 07:29
by nnnik
THX
I'm so stupid. :roll:

Re: Problem when calling a Method

Posted: 07 Apr 2014, 22:15
by lexikos
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.

Re: Problem when calling a Method

Posted: 08 Apr 2014, 09:33
by joedf
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"]