Problem when calling a Method

Get help with using AutoHotkey and its commands and hotkeys
User avatar
nnnik
Posts: 4242
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: 18
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: 4242
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: 18
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: 4242
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: 6483
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

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: 7174
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
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 @ 4.00 GHz, 2x8GB DDR4 2733 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], DRocks, flyingDman, Getfree, Xtra and 146 guests