parent of a nested object

  • Thread starter Thread starter News
  • Start date Start date
N

News

Hi, i have a class like this


Public MustInherit Class MyGeo
...
Public childgeo As New GeometryDrawing
...
End Class


in my window i do something like this

dim a as new MyGeo()

dim list as new list(of GeometryDrawing)

list.add(a.childgeo)


NOW i want to know the parent object (mygeo) of
the list item....
how can i Do?

hope to explain well the proble...

thank U

Alessio
 
Am 24.05.2011 18:34, schrieb News:
Hi, i have a class like this


Public MustInherit Class MyGeo
...
Public childgeo As New GeometryDrawing
...
End Class


in my window i do something like this

dim a as new MyGeo()

dim list as new list(of GeometryDrawing)

list.add(a.childgeo)


NOW i want to know the parent object (mygeo) of
the list item....
how can i Do?

hope to explain well the proble...

thank U

Alessio


As long as the GeometryDrawing class does not have a Parent property,
there is no (unambiguous) answer to this question.

dim d as new GeometryDrawing 'what's the parent of d?

-or-

dim g1 as new MyGeo
dim g2 as new MyGeo

g2.childgeo = g1.childgeo 'one child with two parents?

So, if there's a good reason that a GeometryDrawing object
has always exactly one parent, you can add a constructor to the
GeometryDrawing class taking the parent as a parameter. Make the
child/parent value public through a readonly property in both classes
(if it is not readonly, it takes more efforts to manage parent-child
relations).
 
You cannot do this in the way you are doing.

Your MyGeo class is a mustInherit class, a little bit senseless in this
case.

However,
Public Class Geo
public GeometryDrawings as List (of GeometryDrawing)
End Class

Public Class GeometryDrawing
Public Property Whatever as whatever
End Class

This can make sense

Dim MyGeo as new Geo
MyGeo.Geometrydrawings as new List (of Geometrydrawing)
myGeo.GeometryDrawings.Add(new GeometryDrawing)

Success

Cor
"News" wrote in message
Hi, i have a class like this


Public MustInherit Class MyGeo
...
Public childgeo As New GeometryDrawing
...
End Class


in my window i do something like this

dim a as new MyGeo()

dim list as new list(of GeometryDrawing)

list.add(a.childgeo)


NOW i want to know the parent object (mygeo) of
the list item....
how can i Do?

hope to explain well the proble...

thank U

Alessio
 
Sorry, the class is not mustinherit, is a mistake...

but the geometrydrawing class is not my class, is a framework class that
i cannot modify...
how can i do in this case??

Il 25/05/11 10:55, Cor ha scritto:
 
Il 24/05/11 19:26, Armin Zingler ha scritto:
Am 24.05.2011 18:34, schrieb News:


As long as the GeometryDrawing class does not have a Parent property,
there is no (unambiguous) answer to this question.

dim d as new GeometryDrawing 'what's the parent of d?

-or-

dim g1 as new MyGeo
dim g2 as new MyGeo

g2.childgeo = g1.childgeo 'one child with two parents?

So, if there's a good reason that a GeometryDrawing object
has always exactly one parent, you can add a constructor to the
GeometryDrawing class taking the parent as a parameter. Make the
child/parent value public through a readonly property in both classes
(if it is not readonly, it takes more efforts to manage parent-child
relations).

Sorry, the class is not mustinherit, is a mistake...

but the geometrydrawing class is not my class, is a framework class that
i cannot modify...
how can i do in this case??
 
Am 25.05.2011 11:40, schrieb News:
Sorry, the class is not mustinherit, is a mistake...

but the geometrydrawing class is not my class, is a framework class that
i cannot modify...
how can i do in this case??

If you can inherit from GeometryDrawing, you can add the mentioned constructor
to the inherited class. If not, you can maintain a relation list using the
child as the key to find out it's parent.
 
Than it is even easier
Public Class Geo
public GeometryDrawings as List (of GeometryDrawing)
End Class


Dim MyGeo as new Geo
myGeo.GeometryDrawings.Add(new GeometryDrawing)

So in this way can MyGeo contains a bunch of GeometryDrawings

(as much as you add to that)

In past this was done with the CollectionBase, but I would not know why you
should do that in this case.

Cor

"News" wrote in message

Sorry, the class is not mustinherit, is a mistake...

but the geometrydrawing class is not my class, is a framework class that
i cannot modify...
how can i do in this case??

Il 25/05/11 10:55, Cor ha scritto:
 
Back
Top