get class parent property

hi there,
i have searched through these forums but can’t seem to find an answer on this.
anyone know how to get a property from a class parent

what i have is.
i class named classA
which has all different properties.
one of those properties is ClassB

in classB i have a method.
in that method i want to get a property from the class parent being classA

i thought it would be something like me.parent.propertyname
is this even possible?
thanks for any help :slight_smile:

Ah it’s not a “parent” in the sense of a superClass ?

So the setup would be something like Dictionary (like the kind that you flip through to look up a word) and Word. The Dictionary contains all of its Words, and the Word wants to refer back to a property of its Parent Dictionary, is that it?

Set up the Constructor of ClassB (the Word in my example) so it takes ClassA (the Dictionary) as a parameter. The Constructor will store that reference to ClassA so you can refer to it direction, but do not store it directly. If you do, you will set up a circular reference and create a memory leak.

Instead, create a computed property, Parent As ClassA, and a private property, mParent As WeakRef. In the Constructor, you will:

mParent = new WeakRef( givenClassA )

In the Parent.Get, you will:

if mParent is nil then return nil
dim o as Object = mParent.Resolve
if o is nil then return nil
return ClassA( o )

As long as Dictionary continues to exist somewhere else, Parent will never return nil. Once Dictionary ceases to exist, presumable so will all its Words, so you should still never get nil. (But you should always check for nil anyway, just in case.)

you’d need to make local variable of parent class:

so in childClass, you could write

[code]function test as integer

dim o as ParentClass = self
return o.test

end function[/code]

This way o.test would be property named “test”.

hmm i am getting a little confused. i guess i will have to read up on it more.
this is the exact thing i have…

i have a class leftbaritem (no super) with a few properties. one integer property is named myid
another of the properties named folder is a class cabinetfolder ( no super ) and that property has a method named build
when i run that method as leftbaritem.folder.build i want to be able to in that method get the myid of the leftbaritem

leftbaritem being created with (dim item as new leftbaritem) and being assigned to a rowtag in a listbox.

on a side note. how do i become verified on here? i bought the desktop version.

you are verified if you buy something with credit card.

Your method needs a reference to leftbaritem and can than access the properties there.

How and where is a new cabinetfolder assigned to the folder property?