Accessing a Field by using Object reference ?
BlitzMax Forums/BlitzMax Programming/Accessing a Field by using Object reference ?
| ||
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 |
| ||
Nope, don't think so, sorry. |
| ||
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) |
| ||
I think Armitage wanted to use it everywhere like that, not just in a print statement. |
| ||
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. |