HOWTO: Using the ProjectHook Class to Create a Generic Project

ID: Q192330


The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 6.0


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.

  1. Using the Windows Explorer, create a new folder.


  2. Launch Visual FoxPro 6.0.


  3. Set the default directory to the directory created in step 1.



  4. Create a new ProjectHook Class:

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



    2. Type the following code in the program window:
      **PROJECT HOOK TEST



    3. Save the program as c:\Ph_main.prg and close the program window.



    4. From the File menu, choose New and then select Class.



    5. When the New Class dialog box opens, type the following and then click OK:



    6. Class Name: MyHook
      Based On: ProjectHook
      Store In: HookClass

    7. When the Class Designer window opens, open the INIT method of the class and type the following code:



    8. 
                  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 

    9. Save the class and close the Class Designer.



    10. 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.


    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.



REFERENCES

Visual FoxPro 6.0 Documentation, chapter 32: "Project Manager Hooks"

Additional query words: kbVFp600 kbProjManager

Keywords :
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: February 26, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.