Project Object Hierarchy

The project hierarchy consists of the Projects collection, Project objects in the collection, and a ProjectHook object associated with each project object. A Project object contains a Files collection consisting of project files and a Servers collection consisting of Automation servers created from the project.

The following diagram illustrates the project hierarchy within the Visual FoxPro object model.

Projects Hierarchy

FoxPro Project Object Hierarchy

A Project object is instantiated when a project is created, opened, or rebuilt, or when an application (.app) file, dynamic-link library (.dll) file, or executable (.exe) file is built from the project. When a project associated with a ProjectHook class opens, a ProjectHook object is instantiated by default.

When an event occurs in a project, the Project object passes the event to the ProjectHook object. User code in the event of the ProjectHook object executes and passes control back to the Project object. The value returned to the Project object from the ProjectHook object determines whether the Project object finishes the operation.

Tip

Placing NODEFAULT in the event code prevents the default action from being performed. For example, placing NODEFAULT in the QueryAddFile event of a ProjectHook object prevents a file from being added to a project.

The following sections contain more information about the project hierarchy:

  • Projects Collection in the Project Hierarchy

  • Project Object in the Project Hierarchy

  • ProjectHook Object in the Project Hierarchy

Projects Collection in the Project Hierarchy

The Projects collection provides direct access to Project objects, making it possible for you to manipulate a project and the files and servers that the project contains. When a project is created or opened or when an application (.app) file, dynamic-link library (.dll) file, or executable (.exe) file is built from the project, a project object is added to the projects collection.

You can obtain information about a project in the Projects collection using its properties and methods. For example, the following lines of code show two ways to display the names of all projects in a Projects collection. The first example uses the Count property and Item method of a Projects collection. The second example uses the FOR EACH command.

nProjectCount = Application.Projects.Count
FOR nCount = 1 TO nProjectCount
   ? Application.Projects.Item(nCount).Name
NEXT
FOR EACH oProj IN Application.Projects
   ? oProj.Name
ENDFOR

For more information, see Projects Collection.

Project Object in the Project Hierarchy

A Project object is instantiated when a project is created, opened, or rebuilt, or when an application (.app) file, dynamic-link library (.dll) file, or executable (.exe) file is built from the project. A Project object contains a Files collection consisting of project files and a Servers collection consisting of Automation servers created from the project.

The Project object makes it possible for you manipulate a project programmatically and to access it through an Application object. The Application object has an ActiveProject property that provides an object reference to an open project in the currently active Project Manager.

You can manipulate a Project object through its properties and methods. For more information, see Project Object and Application Object.

Files Collection

The Files collection provides direct access to a File object, which makes it possible for you to manipulate File objects in a project while the project is open. You can manipulate a File object using its properties and methods. For more information, see File Object.

You can add files to a project programmatically. For example, the following line of code uses the ActiveProject property of an Application object to add a program, Main.prg, to the currently active project:

Application.ActiveProject.Files.Add('Main.prg')

The following line of code adds Main.prg to the first project in the Projects collection:

Application.Projects[1].Files.Add('Main.prg')

You can obtain information about a file in a Files collection using its properties and methods. For example, the following lines of code show two ways to display the names of all files in a Files collection. The first example uses the Count property and Item method of a Files collection. The second example uses the FOR EACH command.

nFileCount = Application.ActiveProject.Files.Count
FOR nCount = 1 TO nFileCount
   ? Application.ActiveProject.Files.Item(nCount).Name
NEXT
FOR EACH oProj IN Application.ActiveProject.Files
   ? oProj.Name
ENDFOR

For more information, see Files Collection.

Servers Collection

The Servers collection provides direct access to a Server object, which makes it possible for you to manipulate Server objects that a project contains. You can manipulate a Servers collection through its properties and methods. For more information, see Servers Collection.

When you build a dynamic-link library (.dll) file or executable (.exe) file containing an Automation server from the project, a Server object is added to the Servers collection. For more information about creating Automation servers, see How to: Create Automation Servers in Sharing Information and Adding OLE.

Note

A Server object is not instantiated until the project containing the OLEPUBLIC class, specified in the DEFINE CLASS command, is built. For more information, see DEFINE CLASS Command.

A Server object makes it possible for you to obtain information about Automation servers contained in a project, for example, type library information. This information is also available on the Servers tab in the Project Information dialog box. For more information, see Servers Tab, Options Dialog Box.

You can manipulate a Server object in a Servers collection using its properties. For more information, see Server Object.

ProjectHook Object in the Project Hierarchy

When a project associated with a ProjectHook class opens, a ProjectHook object is instantiated by default.

Tip

To prevent a ProjectHook object from instantiating for the project, include the NOPROJECTHOOK clause in CREATE PROJECT and MODIFY PROJECT commands. For more, see CREATE PROJECT Command and MODIFY PROJECT Command.

The ProjectHook object and allows programmatic access to events that occur in a project. For example, you can execute code when adding a file to a project. The ProjectHook object differs from a Project object, which contains all the properties and methods available in the Project Information dialog box. For more information, see Project Information Dialog Box.

The default ProjectHook class is specified for new projects in the Projects tab of the Options dialog box. You can override the default ProjectHook class by specifying a different project hook class for an individual project in the Project Information dialog box. However, if no default ProjectHook class is specified in the Projects tab, new projects are not associated with a ProjectHook object. For more information, see Projects Tab, Options Dialog Box.

At run time, you can use the ProjectHook property to specify a project hook class for a project. If you change the ProjectHook class for a project, the new ProjectHook class does not take effect until the project closes and opens again.

You can manipulate a ProjectHook object through properties, methods, and events. For more information, see ProjectHook Object.

See Also

Concepts

Project Manager Hooks

Project Object Architecture

Other Resources

Extending Projects in Visual FoxPro

Working with Projects