Accessing field in parent object ?

BlitzMax Forums/BlitzMax Programming/Accessing field in parent object ?

ninomojo(Posted 2008) [#1]
Hello there,


Type TBigObject

Field Smaller_Object:TSmallObject
Field Some_Variable:int = 15

End Type

Type TSmallObject

Method Do_Something()

????????????

End Method

End Type



Let's say that I create an instance of a TBigObject, which contains itself an instance of SmallObject in it field called "Smaller_Object". Is it possible then for Smaller_Object to access a field in its parent object, for example, I would like the Do_Something() method to access "Some_Variable".

Thank you


Gabriel(Posted 2008) [#2]
No, not directly. You either need to give TSmallObject a reference to its parent. Or set a pointer to the integer when you create it.

EG:

Type TBigObject

   Field Smaller_Object:TSmallObject
   Field Some_Variable:int = 15

   Method New()
      Smaller_Object=New TSmallObject
      Smaller_Object.Pointer = VarPtr(Some_Variable)
   End Method
End Type

Type TSmallObject
   Field Pointer: Int Ptr
End Type



ninomojo(Posted 2008) [#3]
Great! Thanks a lot.