Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Is it possible to access the 'this' object from a method called by OnMessage()?


  • Please log in to reply
2 replies to this topic
njciancio
  • Members
  • 141 posts
  • Last active: Sep 14 2014 06:31 PM
  • Joined: 31 May 2012

In this post, with regards to using OnMessage() to call a method of a class, it is stated:

This first parameter is passed as This if a class/object method is called.from OnMessage() as Lexikos already stated.

 

Thus, the this object should be passed as the first parameter, yet it isn't accessible, as below:

Gui, Add, Text, , Click me!
Gui,Show
OnMessage(0x201,"b.a")
class b {
    a(p*) {
        ; "This first parameter is passed as This if a class/object method is called.from OnMessage() as Lexikos already stated."
		msgbox % IsObject(p.1)
    }
}
return
esc::ExitApp

 

Is it possible to access the this object from a method called by OnMessage()? How?


LiveRegExTester - an ahk RegEx testing tool with live result highlighting


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

"This [The] first parameter" refers to the wParam parameter.

"This" refers to the the variable this, which is a hidden parameter of the function b.a.

 

In other words, this contains wParam, not a reference to an object.  p contains the remaining three parameters

 

Try googling the forum for OnMessage object if you need to know more.



njciancio
  • Members
  • 141 posts
  • Last active: Sep 14 2014 06:31 PM
  • Joined: 31 May 2012

In other words, I simply cannot refer to this from within a method called by OnMessage() in the same way as I can from within a typical method. Thanks Lexikos!


LiveRegExTester - an ahk RegEx testing tool with live result highlighting