GLBasic forum

Main forum => GLBasic - en => Topic started by: matchy on 2015-Dec-09

Title: parent.typename like self.typename?
Post by: matchy on 2015-Dec-09
There's self. but how can I reference nested type referencing?   :-[
Logically, should there be parent. also?   :zzz:

Nested TYPE Example:
Code (glbasic) Select

TYPE _item
    id
    selected_id
    color
    size
    FUNCTION set:
         self.id = basket.item_id                    // absolute
//      self.id = parent.parent.item_id       // would prefer relative         
    ENDFUNCTION
ENDTYPE

TYPE _group
    apple AS _item
    banana AS _item
ENDTYPE

TYPE _base
    item_id
    fruit AS _group
ENDTYPE

GLOBAL basket as _base
basket.fruit.apple.set()

Title: Re: parent.typename like self.typename?
Post by: Kitty Hello on 2015-Dec-10
The child has no knowledge about the parent. (Unlike in real life) ;)
Title: Re: parent.typename like self.typename?
Post by: matchy on 2015-Dec-10
Ah. i was hoping it to be like Javascript, which is not real nor life either.  8)
Title: Re: parent.typename like self.typename?
Post by: bigsofty on 2015-Dec-10
You could do it with a little ref passing workaround...

change...
   
Code (glbasic) Select
FUNCTION set:

to...
   
Code (glbasic) Select
FUNCTION set: parentRef as _base

then change...
   
Code (glbasic) Select
self.id = basket.item_id

   to...
Code (glbasic) Select
self.item_id = parentRef.item_id

Your call would need a change too...
   
Code (glbasic) Select
basket.fruit.apple.set(basket)

for another basket...
   
Code (glbasic) Select
basket2.fruit.apple.set(basket2)

Untested.
Title: Re: parent.typename like self.typename?
Post by: matchy on 2015-Dec-11
I see what you mean bigS and I did have something like this. Pardon the complexity and I don't expect a complete solution, although the idea of any type parent was so that it could be generally called, well in this case the fruit may also be not in of basket type (eg. basket, box, bag have item_id).

Code (glbasic) Select


TYPE _container
    item_id
    fruit_sealed AS _group
    fruit_fresh AS _group
ENDTYPE

GLOBAL box as _container  // not the same as _base