Climbing Up an Object Model 
Author Message
 Climbing Up an Object Model

Is there another way to climb back up the object model without making
circular parent references?

An example would be: A Base Parent object called "Transportation". this
transportation object contains a private collection of the "Car" object
called "Cars". and an exposed "Cars" collection property that refers to the
private collection. If i want to access a Car property i would do this:

strColor = Transportation.Cars("Subaru").Color

And i could easily retrieve that information, this is not a problem

But if i want to set that property:
Transportation.Cars("Subaru").Color  = "Blue"
I have to climb up to the Transportation Object from the "Car" object
through the "Cars" Collection.

I know i could have a parent property in both my "Car" object and my "Cars"
collection, but i would like to avoid making circular references.

thanks!

Vinny



Mon, 31 May 2004 23:35:10 GMT  
 Climbing Up an Object Model
Hi.
U got 2 options.

1.
Either U go with objptr()   copymemory....
Which will probably make your server Crash...

2.
Or U do it with weak references.
Use WithEvents

/Er



Tue, 01 Jun 2004 01:50:47 GMT  
 Climbing Up an Object Model
Quote:
> I know i could have a parent property in both my "Car" object
and my "Cars"
> collection, but i would like to avoid making circular

references.

You really have no choice--if you want to link in both
directions, you'll end up with a circular reference.  The
standard way of managing this is to introduce a sort of
destructor that's manually called to release references and do
cleanup so that the object can terminate.

What would also work, is if you could establish a weak reference
to the parent, but I don't know if that can be done in VB.



Tue, 01 Jun 2004 01:51:17 GMT  
 Climbing Up an Object Model
You might want to have a look at Matt Curland's book Advanced Visual Basic
6. It explaines how to make real object hirachies like the ones in MS Word,
and its very safe unlike using weak pointers and copymemory routines.

Regards
Neal


Quote:
> Is there another way to climb back up the object model without making
> circular parent references?

> An example would be: A Base Parent object called "Transportation". this
> transportation object contains a private collection of the "Car" object
> called "Cars". and an exposed "Cars" collection property that refers to
the
> private collection. If i want to access a Car property i would do this:

> strColor = Transportation.Cars("Subaru").Color

> And i could easily retrieve that information, this is not a problem

> But if i want to set that property:
> Transportation.Cars("Subaru").Color  = "Blue"
> I have to climb up to the Transportation Object from the "Car" object
> through the "Cars" Collection.

> I know i could have a parent property in both my "Car" object and my
"Cars"
> collection, but i would like to avoid making circular references.

> thanks!

> Vinny



Tue, 01 Jun 2004 02:52:00 GMT  
 Climbing Up an Object Model

Quote:

> Is there another way to climb back up the object model without making
> circular parent references?

I have written an article explaining one way to do it.
http://www.babbacom.demon.co.uk/Articles/Colls.htm

--
Trevor Prinn
Babbacombe Computers Ltd
http://www.babbacom.com



Tue, 01 Jun 2004 03:09:16 GMT  
 Climbing Up an Object Model
Simple as that...

MsgBox oApp.WoorkBook.Application.WoorkBook.Application.WoorkBook.Name

'<APPLICATION>
Option Explicit
Private WithEvents moWorkBook As WorkBook
Public Property Get WoorkBook() As WorkBook
    If moWorkBook Is Nothing Then
        Set moWorkBook = New WorkBook
    End If
    Set WoorkBook = moWorkBook
End Property
Private Sub moWorkBook_getApplication(oApplication As Application)
    Set oApplication = Me
End Sub
'</APPLICATION>

'<WOORKBOOK>
Option Explicit
Public Event getApplication(oApplication As Application)
Public Property Get Application() As Application
   RaiseEvent getApplication(Application)
End Property
Public Property Get Name() As String
    Name = Now
End Property
'</WOORKBOOK>



Tue, 01 Jun 2004 17:23:48 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Climbing Up an Object Model

2. Report Object Model/Viewer Object Model

3. UPS shipping com object

4. Object-to-Relational Mapping (VB-based Component Object Model)

5. How to climb the wall of inexperience?

6. Climb a point or Pixel ?

7. Need a Pro in Database Modeling (Geographical boundaries Modeling)

8. 3-d models (or modeling) in VB

9. the access object model

10. Access Query in the Object Model?

11. Where is the Access Object model help file?

12. Word object model hWnd

 

 
Powered by phpBB® Forum Software