Enclosing Object

BlitzMax Forums/BlitzMax Beginners Area/Enclosing Object

z80jim(Posted 2006) [#1]
Is there a way for an object that is a field of another object to reference the enclosing object? Sort of like super references the parent object?

For example:
Type TOuterObject
   field innerobject : TInnerObject
end type


I want a method in TInnerObject to be able to call a method in TOuterObject without having to tell TInnerObject who TOuterObject is. It seems TInnerObject must know who it is a member of?

Thanks,
Jim


Dreamora(Posted 2006) [#2]
There is no such facility unless you save a reference to the parent object.


z80jim(Posted 2006) [#3]
Seems like it would be handy and an easy thing to implement in the language. I would think internally the object must be aware of what object it is a member of.


N(Posted 2006) [#4]
>I would think internally the object must be aware of what object it is a member of.

Nope.


Grey Alien(Posted 2006) [#5]
In delphi, every object has a field called owner, handy eh?


N(Posted 2006) [#6]
That's part of its implementation, not the actual language.


Grey Alien(Posted 2006) [#7]
I never said it was part of the language. It's part of the "object" implmentation which everything is descended from.


FlameDuck(Posted 2006) [#8]
What if an object has more than one owner?

I think the most elegant solution is to pass the 'owner' object along as a parameter on any methods you might want to invoke.