Jump to content

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

nested subroutine calling a function


  • Please log in to reply
2 replies to this topic
Rohkk
  • Members
  • 3 posts
  • Last active: Oct 26 2015 11:19 PM
  • Joined: 09 Apr 2015
t := new Test

Class Test {
 __New(){
  this.initGui()
  this.initComponents()
 }

 initGui(){  
  Gui, Show, x127 y87 h379 w479, Test
  return
 }

 initComponents(){
  global
  Gui, Add, Button, x12 y339 w130 h30 , Test
 }

 initActions(){
  ButtonTest:
   MsgBox clicked test button
   this.test()
  return
 }

 test(){
  MsgBox test button alert 2
 }
}

the button is calling the subroutine inside of initActions, which is calling the class function test(), however this does not activate on button press

 

how can i make this test() function activate? 

 

I currently get output: 

clicked test button

 

but i want output in 2 message boxes

clicked test button

test button alert 2



space
  • Members
  • 520 posts
  • Last active:
  • Joined: 12 Aug 2014
Probably wrong and I don't understand why but if you add "this line" it works.
Class Test {
  static init:="".base.base := test ; add this line


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

this is a local variable - an implicit parameter of the method initActions, set when you call something.initActions(). If you never call the method, this will be empty. If you call the method and it returns, this will be empty.

 

Instead of using a sub, use a bound function:

fn := this.initActions.Bind(this)
GuiControl +g, Button1, % fn

 

space: That would make ("").test() "work" too...