to send Self to a function using tevent + hook

BlitzMax Forums/BlitzMax Programming/to send Self to a function using tevent + hook

CS_TBL(Posted 2007) [#1]
SuperStrict

Type Ttest

	Field a:Int=1
	Field b:Int=2
	Field c:Float=3.5

	Field newevent:TEvent=New TEvent
	
	Function eventhook:Object(id:Int,data:Object,context:Object)
		If Ttest(context) Ttest(context).ev TEvent(data);Return data	
	EndFunction
	
	Method New()
		AddHook EmitEventHook,eventhook,Self
	End Method
	
	Method Free()
		RemoveHook EmitEventHook,eventhook
		GCCollect()
	End Method
	
	Method ev(event:TEvent)
	
		If event.id=$999666
			DebugLog "***"
			newevent.id=$999555
			newevent.data=Self ' <- the issue, ".source" works tho.
			EmitEvent newevent
		EndIf
	End Method
	
End Type

Function test2:Object(id:Int,data:Object,context:Object)
	Local ev:TEvent=TEvent(data)
	
	If ev.id=$999555
	
'		Local p:Ttest=ev.data ' <- the issue
'		debuglog p.a
'		debuglog p.b
'		debuglog p.c
	EndIf
	
	Return data
EndFunction

AddHook EmitEventHook,test2




Local t:Ttest=New Ttest

Local a:TEvent=New TEvent

a.id=$999666
EmitEvent a
End



ok, fair enough: how to get test "Self" to that test2 function so I can read out test's stuff there?


skidracer(Posted 2007) [#2]
Either event.source or event.extra can contain an object, event.data is an integer for things like keycodes etc.


CS_TBL(Posted 2007) [#3]
so, what's the solution?

"newevent.data=Self" results in an error..
.source and .extra works, but then how to get access to the object again in that test2 function?


CS_TBL(Posted 2007) [#4]
Found it! May this code serve thou!