Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Projects

Projects is a collection (an array property) that gives you access to all open projects. It’s a property of the _VFP and Application objects.

Usage

oProject = appApplication.Projects[ nIndex ]
appApplication.Projects[ nIndex ].Property = uValue
appApplication.Projects[ nIndex ].Method()

One of the big changes in VFP 6 is the ability to access projects and their contents programmatically. This makes it easier to write all kinds of cool tools to manipulate projects. The Projects collection is the first step in the process. It contains one element for each open project. The items in the collection are Project objects (try saying that one 10 times fast). The collection’s Count Property tells you how many there are.

To access the Projects collection, you need to use either the _VFP variable or the Application Object. Projects is an ActiveX collection, not quite fully native to VFP. In practice, this means that any errors you get are OLE errors rather than native VFP errors.

Beware: As you open projects, the ones that are already open get pushed farther and farther down in the collection. That is, the most recently opened project is Projects[1] while the first project you opened is at the end of the collection. However, bringing a project to the front doesn’t change its place in the collection.

Example

* Open a few projects.
* Now to see what's open:
FOR EACH oProj IN Application.Projects
   ?oProj.Name
ENDFOR
* How many projects are open?
? Application.Projects.Count

See Also

ActiveProject, Application, Count Property, Project, _VFP