Convert from byte ptr to object?

BlitzMax Forums/BlitzMax Programming/Convert from byte ptr to object?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Can't you use HandleFromObject and HandleToObject instead of byte ptrs?

Otherwise this dirty (which may fail in a million different cases) trick can be used:
Type TJimmy
	Global list:TList = New TList

	Field great:Int = 1234
	
	Method New()
		list.addlast Self
	EndMethod
	
	Function FromBytePtr:TJimmy(b:Byte Ptr)
		For Local j:TJimmy = EachIn list
			If Byte Ptr(Varptr(j))[0] = b[0]
				Return j
			EndIf
		Next
	EndFunction
EndType

New TJimmy
Local j:TJimmy = New TJimmy
j.great = 1456
Local k:Byte Ptr = Varptr(j)
Local i:TJimmy = TJimmy.FromBytePtr(k)

If i
	Print "Jimmy.great = "+i.great
Else
	Print "Couldn't find Jimmy!"
EndIf