Hotkey makes class objects un-freeable Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Hotkey makes class objects un-freeable

21 Nov 2017, 21:38

how do i remove the reference used by Hotkey? It's preventing the object from freeing properly.
example:

Code: Select all

t := new test()
t := ""
return

Class test {
    __New() {
        f_func1 := ObjBindMethod(this, "func1")

        Hotkey, CapsLock, %f_func1%, On
        Hotkey, CapsLock, %f_func1%, Off
    }

    func1() {
        ToolTip, % "hello world"
    }

    __Delete() {
        ToolTip, % "object deleted"
    }
}
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Hotkey makes class objects un-freeable  Topic is solved

21 Nov 2017, 22:41

Hi KuroiLight,

Here's a solution. I don't know if it is the only one and, in particular, the less hard-coded and efficient one (btw I already gave you an example on how hotkeys makes class objects un-freeable in a previous post).

Code: Select all

t := (t:=new test()).free()
return

Class test {
    __New() {
	MsgBox,,, % A_ThisFunc, 1
    f_func1 := this.f_func1 := ObjBindMethod(this, "func1")
    Hotkey, CapsLock, %f_func1%, On
    }
	free() {
	randomFunc := Func("WinActive").bind("A")
	Hotkey, CapsLock, % randomFunc, On
	this.f_func1 := ""
	return ""
	}
    func1() {
    ToolTip, % "hello world"
    }
    __Delete() {
	MsgBox,,, % A_ThisFunc, 1
    }
}
If you're looking for a general solution you can take a look at this [francophone forum] Hotkey OOP wrapper for the hotkey command I made a short time ago (you'll also find there a link to RUNIE's one from which I build it) and which implement a delete method.
my scripts
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: Hotkey makes class objects un-freeable

21 Nov 2017, 23:13

That worked, it's unfortunate that hotkey doesn't have a Delete option to free up the reference...

Code: Select all

#SingleInstance, force
t := new test()
Sleep, 1000
t.Dispose()
t := ""
Sleep, 2000
ExitApp, 0
return

Class test {
    __New() {
        f_func1 := ObjBindMethod(this, "func1")

        Hotkey, CapsLock, %f_func1%, On
        Hotkey, CapsLock, %f_func1%, Off
    }

    func1() {
        ToolTip, % "hello world"
    }

    Dispose() {
        f_func1 := Func("WinActive").bind("A")
        Hotkey, CapsLock, %f_func1%, On
        Hotkey, CapsLock, %f_func1%, Off
    }

    __Delete() {
        ToolTip, % "object deleted"
    }
}
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww, ulysim and 324 guests