OnEvent Error

Discuss the future of the AutoHotkey language
User avatar
emmanuel d
Posts: 90
Joined: 17 Nov 2013, 04:45

Re: OnEvent Error

02 Jul 2021, 10:51

This does not work anymore, i get this message:

Code: Select all

Error:  Unknown method.
Specifically: Event_Close
did the syntax changed again?
iPhilip wrote:
23 May 2019, 15:38

Code: Select all

myGui := GuiCreate(,, Events)  ; Events is the "event sink object"
myGui.AddText("", "Press Alt+F4 or the X button in the title bar.")
myGui.OnEvent("Close", "Event_Close")  ; Callback is a method registered by name: Event_Close
myGui.Show

class Events {
   Event_Close(thisGui) {
      MsgBox "Closing Gui: " thisGui.title "`nand exiting."
   }
}
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: OnEvent Error

02 Jul 2021, 11:24

GuiCreate() is no more, use Gui()
the other thing that changed is instance methods are separate from class(static) methods. either create an instance of Events and use that as the sink or turn the instance method Event_Close into class method.

Code: Select all

#Requires AutoHotkey v2.0-a128+

myGui := Gui(,, Events)  ; Events is the "event sink object"
myGui.AddText("", "Press Alt+F4 or the X button in the title bar.")
myGui.OnEvent("Close", "Event_Close")  ; Callback is a method registered by name: Event_Close
myGui.Show

class Events {
   static Event_Close(thisGui) {
      MsgBox "Closing Gui: " thisGui.title "`nand exiting."
   }
}

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 27 guests