Accessing a Field by using Object reference ?

BlitzMax Forums/BlitzMax Programming/Accessing a Field by using Object reference ?

Armitage 1982(Posted 2009) [#1]
Hi

For the purpose of an Object Inspector Tool I created different type in order to manipulate primitive type like int, float, etc.

I create a field inside to receive the primitive and modify it with specific methods.

But to access this primitive I still need to do something like :
Local managed:Type_int = Type_int.create(10) 'Simply set the  Field myInt:int and return a Type_int object
print managed.myInt


Is there any solution to directly access the primitive Field by using the reference object ?
Local managed:Type_int = Type_int.create(10) 'Simply set the  Field myInt:int and return a Type_int object
print managed


This would clean my code a lot !
Thanks


Warpy(Posted 2009) [#2]
Nope, don't think so, sorry.


fredborg(Posted 2009) [#3]
Print Int Ptr(Byte Ptr(managed))[0]
Beautiful :)

Or a little more complex:
Type Type_Int
	Field value:Int
	Method ToString:String()
		Return value
	EndMethod
	Function Create:Type_Int(value:Int)
		Local t:Type_Int = New Type_Int
		t.value = value
		Return t
	EndFunction
EndType

Function sPrint(o:Object)
	Print o.ToString()
EndFunction

Local managed:Type_int = Type_int.Create(10) 'Simply set the  Field myInt:int and return a Type_int object
sPrint(managed)



Warpy(Posted 2009) [#4]
I think Armitage wanted to use it everywhere like that, not just in a print statement.


Armitage 1982(Posted 2009) [#5]
Warpy
I think Armitage wanted to use it everywhere like that, not just in a print statement.


Exactly
But thanks anyway fredborg those are interesting piece of code to learn from.