Microsoft KB Archive/192330

= HOWTO: Using the ProjectHook Class to Create a Generic Project =

Article ID: 192330

Article Last Modified on 2/27/1999

-

APPLIES TO


 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q192330



SUMMARY
Visual FoxPro 6.0 introduces a project object association model and a new ProjectHook class for use specifically with projects. These additions allow developers to programmatically manipulate a Visual FoxPro 6.0 project as an object. This document demonstrates how to create a new ProjectHook baseclass, and configure Visual FoxPro to instantiate the ProjectHook class each time a project is created or modified.



MORE INFORMATION
Prior to the introduction of Visual FoxPro 6.0, programmatic changes to a Visual FoxPro project could only be accomplished by manipulating the project's .pjx file.

 Using the Windows Explorer, create a new folder. Launch Visual FoxPro 6.0. Set the default directory to the directory created in step 1.

 Create a new ProjectHook Class:

 

 From the File menu, choose New, and then select Program.

 Type the following code in the program window:


 * PROJECT HOOK TEST

</li> Save the program as c:\Ph_main.prg and close the program window.

</li> From the File menu, choose New and then select Class.

</li> When the New Class dialog box opens, type the following and then click OK:

Class Name: MyHook

Based On: ProjectHook

Store In: HookClass

</li>  When the Class Designer window opens, open the INIT method of the class and type the following code:

LOCAL cPrgPath IF !FILE('PH_MAIN.PRG') cPrgPath = _vfp.ActiveProject.homedir+"\PH_main.prg" COPY FILE C:\PH_MAIN.PRG to (cPrgPath) _VFP.ActiveProject.Files.Add(cPrgPath) ENDIF

</li> Save the class and close the Class Designer.

</li> Configure Visual FoxPro to use the ProjectHook class. a. From the Tools menu, choose Options, and then click the Projects tab. b. Select the Project Class check box on the bottom of the Projects tab. c. In the text box next to the Project Class check box, enter the path to the class created in step 4.</li></ol>

Now test the ProjectHook class by creating a new project. Note that when the project is created, the MyHook class is instantiated and the Ph_main.prg file is copied to the currently selected directory and included in the newly created project.</li></ol>

<div class="references_section">