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.
This collection contains one item for each file in a project. It’s part of the scheme added in VFP 6 for handling projects and their contents programmatically.
prjProject.Files.Method()
prjProject.Files[ nIndex ].Method()
uValue = prjProject.Files[ nIndex ].Property
prjProject.Files[ nIndex ].Property = uValue
The Files collection gives you access to all the items in a project. It’s an array in which each element is a File object. The collection has only one property of its own, Count, which tells how many files there are. There are a couple of methods that operate on the collection as a whole. Add adds a new file to the project. Item gives you access to an individual file. We can’t see why you need Item—you can do the same thing simply by referencing Files[ nSomeItem ], but it’s an OLE thing. Like Projects, Files is an ActiveX, rather than a native, collection. Most of the time, this isn’t an issue, but it probably does have an effect on system resources. For sure, the error messages you get when you mess up on this stuff are OLE errors, not native VFP errors.
In the original release of VFP 7, the Files collection doesn't always get updated when it should. When you add a file other than a program (say, a form or menu), it doesn't show up in the Files collection, and Files.Count doesn't change for a while. Closing and reopening the project fixes the problem, but what a pain! Since this bug is likely to break a huge percentage of the project hooks out there, we're not surprised that it's fixed in SP1. |
* List all the files in the active project.
FOR EACH oFile IN Application.ActiveProject.Files
?oFile.Name
ENDFOR
Add, Count Property, File, Item, Project