[a131] Gui_DropFiles crash if Event Sink used Topic is solved

Report problems with documented functionality
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

[a131] Gui_DropFiles crash if Event Sink used

17 Apr 2021, 20:56

https://github.com/Lexikos/AutoHotkey_L ... 659f0R1193
there are several ways to hook up events in v2. one is by defining a function that would handle the event and providing a reference to it to .OnEvent()

Code: Select all

#Requires AutoHotkey v2.0-a131-2327728b

G := Gui()
G.OnEvent('DropFiles', Gui_DropFiles)
Gui_DropFiles(GuiObj, GuiCtrlObj, FileArray, X, Y) {
	MsgBox(FileArray.Length ' file(s) dropped.')
}

G.Show('w200 h200')

another is by specifying an EventSinkObj and passing the name of an instance method of the specified EventSinkObj as a string to .OnEvent()

Code: Select all

#Requires AutoHotkey v2.0-a131-2327728b

G := MyGui()

class MyGui extends Gui {
	__New() {
		super.__New('', '', this)
		this.OnEvent('DropFiles', 'Gui_DropFiles')
		this.Show('w200 h200')
	}

	Gui_DropFiles(GuiCtrlObj, FileArray, X, Y) {
        MsgBox(FileArray.Length ' file(s) dropped.')
	}
}
notice the signature of the method differs from that of the function in the previous example.
problem: if u drop files on the EventSink example, the script crashes once the event handler callback starts going out of scope
solution: linked code needs adjusted to account for the shift in the handler's parameters(so it doesnt keep trying to cast X - an integer, to an object and call ->Release() on it)

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 51 guests