Hook Unhook?

BlitzMax Forums/MaxGUI Module/Hook Unhook?

Baystep Productions(Posted 2008) [#1]
So I have a program that creates a window with basic gadgets and all. And I use AddHook so that the main program can still have control. Kind-of like the window is a tool. So I press a key to open the window and it sets up fine, everything works great. But when I close it, and try and open it again I get an UE on a NULL OBJECT error, and its called on my event.id line for parsing through what called it. I'm assuming its a problem with removehook and then trying to add it again.

Btw the window is created and controlled through a type class in a method. Just like the tutorial.

So I would like to know, how do I destroy the type instance along with the hook so I can easily start it again clean later?


jsp(Posted 2008) [#2]
Remove the hook with RemoveHook() and kill the instance with instance=Null.
Or post some code that we can see the problem.


Baystep Productions(Posted 2008) [#3]
Type IDBWin
         ...
         Method Create:IDBWin(name$,width%,height%)
		'Local a:IDBWin
		  dbg_win=CreateWindow(name$,200,200,width%,height%,Null,WINDOW_TITLEBAR)
		dbg_varSelect=CreateTreeView(5,5,282,200,dbg_win)
		For getGrp:IDB_GROUP = EachIn IDB_GList
			getGrp.tnode=AddTreeViewNode(getGrp.name$,dbg_varSelect)
			For Local tVar:IDB_VARIABLE = EachIn getGrp.varList
				tVar.tnode=AddTreeViewNode(tVar.name$,getGrp.tnode)
			Next
		Next
		dbg_desc=CreateLabel("Description: ",5,210,282,20,dbg_win)
		dbg_dtype=CreateLabel("Data Type: ",5,230,282,20,dbg_win)
		dbg_defv=CreateLabel("Default Value: ",5,250,282,20,dbg_win)
		dbg_inp=CreateTextField(5,270,200,24,dbg_win)
		dbg_setb=CreateButton("SET",207,270,77,24,dbg_win,BUTTON_PUSH)
		SetGadgetText(dbg_inp,"VALUE")
		DisableGadget(dbg_inp) 
		
		AddHook EmitEventHook,eventHook,Self
		Return Self
	EndMethod
        Method Destroy()
	     RemoveHook EmitEventHook,eventHook
	     FreeGadget(Self.dbg_win)
        EndMethod
        Function eventHook:Object(id,data:Object,context:Object)
             Local app:IDBWin
	     Local event:TEvent
	     event=TEvent(data)
	     app=IDBWin(context)
	     app.OnEvent event	
        End Function
        ...
EndType
Function idb_GUIOpen(idb:IDBWin)
	idb = New IDBWin.Create("Test",300,400)
EndFunction
Function idb_GUIClose(idb:IDBWin)
	idb.Destroy()
	idb = Null
EndFunction



SebHoll(Posted 2008) [#4]
Well, my first thoughts are that you aren't specifying the context to remove in your Destroy() method. You need to specify the context with which you called AddHook:

RemoveHook EmitEventHook,eventHook,Self
Does that help at all?


Baystep Productions(Posted 2008) [#5]
I'll try...

And bingo. Works. Thanks.