Objects
This collection property gives you a handle to all the objects instantiated in an instance of VFP. It's convenient for writing generic tools and especially useful for Automation servers. It also lets you look inside VFP's container classes.
Usage |
oObject = oContainer.Objects[ nIndex | cName ] |
You can manipulate at least some of the design-time objects that show up in the _VFP.Objects collection, but in VFP 6, we found it a dangerous game to play. We crashed or froze VFP more often in a couple of hours playing with the Objects collection than in weeks of doing other stuff. So far, in VFP 7, this collection seems a lot more stable. |
In earlier versions, getting access to the Objects collection at runtime is flaky. As long as you're drilling down directly from the _VFP application object, all is well. But if you create an object reference to, say, a form, VFP can't see the Objects collection. That is, ? _VFP.Objects["frmMyForm"].Objects.Count tells you the number of controls on the form. But: oForm = _VFP.Objects["frmMyForm"] ? oForm.Objects.Count gives an error message. This bug is fixed in VFP 7. |
Unfortunately, there's a nice new bug to replace it. When you use an object reference to drill down, and use the Item method to address the members of the collection, you get an error unless you got the object reference by drilling down from _VFP. That is, with a form running, this code works: ? _VFP.Objects["frmMyForm"].Objects.Item[1].Name but this doesn't: oForm = _SCREEN.ActiveForm ? oForm.Objects.Item[1].Name And, assuming the form is called MyForm, neither does this: ? MyForm.Objects.Item[1].Name We think this is a deeper manifestation of the earlier bug. Fortunately, you can work around it by using the shorthand notation: ? oForm.Objects[1].Name |
But wait, there's more. IntelliSense mishandles the Objects collection. At the application level (that is, for _VFP.Objects), no IntelliSense is available—that is, no members pop up after you hit the period. Below that level, only Count is offered as a choice (except, sometimes, when Value appears instead). The Item method never shows up, and when you specify an index, IntelliSense doesn't offer you the members of the specified object. |
Example |
* Find out what objects exist. FOR EACH oObj IN _VFP.Objects ? oObj.Name ENDFOR |
See Also |
Application, Buttons, ButtonCount, Columns, ColumnCount, Controls, ControlCount, Count Property, CreateObject(), Forms, FormCount, NewObject(), Pages, PageCount, _VFP |