Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Objects in a collection
Message
 
 
To
11/10/2003 14:52:52
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00837839
Message ID:
00838366
Views:
19
Rick,

If your collected objects all inherit from a common "collection aware" baseclass you could add a custom oParentCollection property and populate it with a reference to the collection. You will be responsible for clearing this object ref so everything will destruct properly.
ocoll = createobject( "mycollection" )
ocoll.Add( createobject( "collected", oColl ), "1" )
ocoll.Add( createobject( "collected", oColl ), "2" )
oColl.Item( "1" ).DoIt()

define class collected as custom
oParentCollection = .null.

function Init( roCollection )
this.oParentCollection = roCollection
return dodefault()
endfunc

function DoIt()
this.oParentCollection.DoIt()
endfunc

enddefine

define class mycollection as collection
function DoIt()
? "I did it"
endfunc
enddefine
This means you are pretty tightly coupling your collected objects to the collection itself. There may be some other design pattern that will help you accomplish your end goal.

>I've started using collection classes to hold multiple objects. I would either like to get the objects in the collection to inherit properties of the collection class when they are Added to the collection, or be able to reference the properties of the collection class from the object in the collection. The objects in the collection are "owned" by the collection class in the way they are by a container class so I can't use the Parent designation. Is there any easy way to reference methods and properties of the collection from the collection's objects?
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Reply
Map
View

Click here to load this message in the networking platform