Page 1 of 1

[v1/v2] Problem with __delete meta function for object associated with gui control event

Posted: 23 Sep 2017, 16:27
by Helgef
Hello :wave:
I'm having issues with the __delete meta function not being called for an object which has been set to handle a guiControl's events, see this script,

Code: Select all

z:=new test
gui, new
gui, add, button, hwndbtn
o:=z.f.bind(z)
guicontrol, +g, % btn, % o ; comment/uncomment to see the problem
exitapp
class test {
	__delete(){
		msgbox
	}
	f(){
	}
}
Comment/uncomment the marked line to see the issue. Binding to a non-method function presents the same issue. I have the same problem with the corresponding v2 code.
Could someone explain my mistake to me, or why this happens? :eh:
Thanks for your time, cheers.

Re: [v1/v2] Problem with __delete meta function for object associated with gui control event  Topic is solved

Posted: 23 Sep 2017, 16:39
by A_AhkUser
Hi Helgef,

I think it is necessary to free the object which has been set to handle a guiControl's events - i.e.:

Code: Select all

OnExit("freeControl")
z:=new test()
gui, new
gui, add, button, hwndbtn
o:=z.f.bind(z)
guicontrol, +g, % btn, % o
exitapp
class test {
	__delete() {
		msgbox
	}
	f(){
	}
}
freeControl() {
global btn
guicontrol, -g, % btn
}

Re: [v1/v2] Problem with __delete meta function for object associated with gui control event

Posted: 23 Sep 2017, 16:47
by Helgef

Code: Select all

guicontrol, -g, % btn
Yeah, now that you say it I recognise this :facepalm: :lol:
Thanks!

Edit: For reference, this suffice,

Code: Select all

gui.onEvent("close","f")

onGuiClose(hgui){
	hgui.destroy()
}

Re: [v1/v2] Problem with __delete meta function for object associated with gui control event

Posted: 23 Sep 2017, 17:23
by A_AhkUser
In truth, I hurry to reply; this was an opportunity: It was the world upside down, I think it is the first and last time I could help you. :lol:

ahk v1 version:

Code: Select all

z:=new test()
gui, new
gui, add, button, hwndbtn
o:=z.f.bind(z)
guicontrol, +g, % btn, % o
gui, destroy
exitapp
class test {
	__delete() {
		msgbox
	}
	f(){
	}
}

Re: [v1/v2] Problem with __delete meta function for object associated with gui control event

Posted: 23 Sep 2017, 17:56
by Helgef
I mean gui.destroy() suffice for my purpose, guicontrol, -g, % btn is the general solution, we do not want to have to destroy the gui to release the object, in general. :wave:
It seems I cannot really do the equivalent in v2, I need to do guiCtrl.onEvent("eventName", referenceToTheObejct, 0), so I need to refrence the object when I unregister it for the event :think: :cry:. (Note: I don't know much about guis, take my statements with a pinch of salt and please correct me.)

Cheers.