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.

MainFile, MainClass, SetMain

These properties and method indicate and control the main file in a project—that is, the one that gets executed first when the project is run. MainFile and MainClass tell you what the main file is, while SetMain lets you set it programmatically. MainFile and MainClass correspond to the bolded entry in the Project Manager; SetMain is the equivalent of the Set Main option on the Project menu.

Usage

cMainFile = prjProject.MainFile
cMainClass = prjProject.MainClass
lMainChanged = prjProject.SetMain([ cMainFile [, cMainClass ]])

Parameter

Value

Meaning

cMainFile

Filename including extension

The starting program or form of a project, or the class library containing the starting ActiveDoc.

Empty string

No main file is designated for this project.

cMainClass

Class name

The starting Active Document class of a project.

Omitted

Either the main file is a program or no main file is designated for this project.

lMainChanged

.T.

The main file was changed.

.F.

The main file was not changed.

MainFile contains the name of the file marked as main. If the main object in the project is an active document, MainFile contains the class library while MainClass contains the actual name of the ActiveDoc class. If you pass a class name but no class library, VFP sets the project to have no main file (as if you’d passed only the empty string).

Since the main program for a project can actually be a program, a form or a class, SetMain requires the extension. However, the path to the file is not required, although you can include it. On the other hand, MainFile always reports the complete path.

The return value of SetMain is weird. The method returns .T. only if you actually change the main file. So if you call SetMain with the current main file, it returns .F. We were misled into thinking that a call didn’t work for quite a while until we caught on.

Example

* Assume the active project contains an active document
* class named 'acdFred' in a classlib called 'MyActiveDocs'
Application.ActiveProject.SetMain("MyActiveDocs.VCX","acdFred")

* Find out about the main program of a project referenced
* by the variable oProj.
?oProj.MainFile, oProj.MainClass

See Also

ActiveDoc, Project, Projects