What's up with collections in VFP?
During the storied history of Visual FoxPro, we went from having no native collection class, so we coded our own home grown collections, to the current day when we have seemingly many types and nuances of collections. Today the central difficulty is: the type of collection you get depends on the semantics of use.
- Foremostly, starting in VFP 8, we have a native collection class and these are very common in newer systems, and very slowly replacing VFP home grown collections in older, legacy systems.
- VFP has several native properties designed to behave like collections, including:
_SCREEN.Forms which is a VFP collection.
_VFP.Forms which is a COM collection.
- VFP container classes all have an
.Objects collection, which behave either as VFP collections or COM collections. See below, and see also the objects collection topic.
- Individual container classes have semantic collections, such as:
These are all largely considered vestigial, but they'll be supported forever.
.Columns collection for Grids,
.Pages collection for Pageframes,
.Controls collection for Forms,
.Buttons collection for Optiongroup and Commandgroup classes,
- If you iterate through a collection using
FOR EACH... you get a COM collection (COM references) even though you are iterating through VFP objects.
Didn't this change in VFP 9 with the addition of the
FOXOBJECT keyword to the
FOR EACH... statement?
It seems so, in this article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_foxhelp9/html/b21ba88f-aeda-48e0-a3c5-de9984020281.asp
- If you iterate through a collection using array syntax, for example
oFoo.Objects, you are seeing a VFP collection and therefore get VFP object references.
--> Therefore beware that there is no single definition of "collection" in VFP, and what you get, exactly, is subtly determined by usage.
Category VFP Properties, Category VFP Controls, Category VFP Troubleshooting
( Topic last updated: 2005.03.21 08:31:53 AM )