Session E-STUD

Integrating Visual FoxPro with Visual Studio 6.0

Rod Paddock
Dash Point Software, Inc


Introduction

Visual FoxPro is a member of the Visual Studio family of development tools. Being a member of Visual Studio has a number of advantages. The primary advantage is the ability to be able to use the many tools that comprise the Visual Studio Suite. In this session we will explore three tools in the Visual Studio Family that Visual FoxPro integrates with well. In this session we will cover:

How to Use Visual FoxPro with Visual Modeler

The first tool to explore is Visual Modeler. Visual Modeler is an object modeling tool that ships with the Visual Studio Enterprise Edition. Visual Modeler is a sub-set of the Rational Rose object modeling tool from Rational Corporation.

Visual Modeler is a simplified modeling tool that is best used to develop multi-tier applications. While not as powerful as Rational Rose provides a good introduction to the world of object modeling at a low cost. Visual FoxPro integrates with Visual FoxPro in two ways:

The integration of Visual Modeler and Visual FoxPro happens with the help of two wizards that were developed for such a purpose.

 
Note: You can download the Visual FoxPro/Visual Modeler wizards from the following web address:www.msdn.microsoft.com/vfoxpro/downloads/updates.asp You will be required to register before downloading this set if wizards.

Creating a Model

The first step in using Visual Modeler with Visual FoxPro is to create a model. To launch Visual Modeler you select Microsoft Visual Modeler from the Visual Studio Enterprise Tools menu. Once you have opened Visual Modeler you can begin creating a new class. To create a new class right click on one of the three tiers (User Services, Business Services or Data Services) presented in your model. Select New-Class from the popup menu. This will add a new class to your model. Once a class has been added you can begin describing that class. To describe the attributes of class right-click on that class and select Open Specification from the popup menu. You will now be prompted with the Class Specification Dialog (See figure 1) this dialog lets you specify the elements of your class including the class name, properties and methods.

Figure 1 The Class Specification Dialog

To add a property you will use the Properties tab. To add a property select the Properties tab, Right click in the editing box and select Insert from the popup menu. This will add a property to the list which will now allow you to specify the name and data type for that property. To edit the attributes of a property double click on that property.

Upon completing your class definition save it to disk. You can now go through the process of using the Visual FoxPro/Visual Modeler wizards.

Exporting Models to VFP

The first item to explore is exporting models to Visual FoxPro from Visual Modeler. To run the Visual Modeler Wizards change to the directory (or set path to that directory) where you installed your wizards. In the Command Window Type: DO VFPMODEL From the dialog that appears select the Code Generation Wizard. This wizard will export a model to a set of VFP classes.

Once this wizard is activated it will take you through a number of steps. These steps are:

Importing Existing Classes

One of the other capabilities of the Visual FoxPro Modeling wizards is the ability to import existing classes into Visual Modeler. To import classes you simply activate the wizard again and select Reverse Engineering Wizard from the dialog. This wizard will also take you through a number of steps. These steps are:

As you can see the Visual Modeling wizards provide a great set of useful functionality for Visual FoxPro developers.

Using Visual Basic

The next tool to examine is Visual Basic. Visual Basic provides a great deal of functionality that can be used by Visual FoxPro developers in their development. Some of the areas to look at include:

In this session we will take a look at two of these capabilities Visual Basic's IntelliSense and Visual Basic's Object Browser.

Using IntelliSense

One of the most valuable features Visual Basic has to offer Visual FoxPro developers is its great IntelliSense integration. If you have ever attempted to integrate your applications with Microsoft Excel or Microsoft you know that navigating an object model can be a difficult process. Visual Basic removes a great deal of this difficulty. To take advantage of Visual Basic's IntelliSense you first need to create a Visual Basic project. To do this activate VB from the Windows Start bar and select Standard EXE from the New Project Dialog.

Once you have created a project you need to add a reference to the object model you wish to navigate. You add references by selecting Project-References from the VB menu. When you do this you will be presented with a dialog that allows you to select different object models (Figure 2).

Figure 2 VB Project References Dialog

Once you have added your reference double click on the VB form designer this will take you into the VB code editor. Add the following code to the code area:

Now you can navigate the object model of Excel by addressing the x variable. The demonstration will show you how to navigate the Object hierarchy of Microsoft Excel.

Using the Object Browser

Visual Basic also includes an object browser. This browser allows you to explore object models much like you would use VFP's Class Browser. To activate the Object browser press the F2 key. This will activate the Object Browser. The most useful aspect of this tool is finding the Values of VBA or OLE constants. Navigating down the Classes window will show you the constants specified for various object model items. You can navigate further into these lists of constants by selecting the specific values from the Members window. Figure 3 shows you the Object browser with the xlChartType constants selected. (Look in the bottom window for the numeric value of that named constant)

In just a few short minutes you learned two very valuable aspects of VB for Visual FoxPro developers. Now lets look at the last tool Visual Interdev.

Integrating Visual FoxPro and Visual InterDev

The final tool to examine is Visual InterDev. Visual InterDev is the web development tool provided in the Visual Studio Suite. Visual InterDev can be integrated with Visual FoxPro in two ways. You can integrate Visual FoxPro data using ODBC/OLE-DB and you can consume ActiveX servers created with Visual FoxPro. Let take a look at these two items.

Consuming Visual FoxPro Data with VI

The first item to look at is consuming VFP data with Visual InterDev. To do this complete the following steps:

  1. Create an ODBC DSN to your VFP DBC.
  2. Create a new Visual InterDev project.
  3. After your project is created select Project-Add Data Connection from the VI menu.
  4. Select your ODBC DSN from the provided dialog. (Press OK in the dialog that follows)
  5. Create a new Active Server Page by selecting Project-Add Web Item-Active Server Page from the VI menu.
  6. Select the Design View tab for your ASP page.
  7. Select the Design Time Controls option in the VI toolbox.
  8. Drag and drop a Recordset object onto your ASP page The Connection parameter should default to your connection.
  9. Drag and drop a Grid object onto your form.
  10. Right click on the Grid and select Properties from the popup menu.
  11. Select the Data tab.
  12. In the Recordset Property specify the recordset you created in step 8
  13. Select the fields you wish to display.
  14. Set other visual properties for your grid.
  15. Close the property pages by selecting OK.
  16. Right click on your page and select View in Browser from the popup.

You should now see the contents of your table in an HTML grid.

Integrating VFP Components

One of the other capabilities in VI is its ability to integrate with COM components. Visual InterDev uses Active Server Pages as its primary tool for developing web applications. ASP has language constructs that allow you to integrate COM components with little code. The following code demonstrates calling a VFP COM component with ASP.

  1. Create a VFP COM component called VFPCOM.VIDEMO. This component should have method called GetDateTime() that returns the current DateTime()
  2. Add an Active Server Page to your web site by selecting Project-Add Web Item-Active Server Page from the VI menu.
  3. Add the following code to your ASP page.
    <%      
    Set oFoxPro = Server.CreateObject("VFPCOM.VIDDEMO")      
    Response.Write("The current date and time is:" <%=oFoxPro.GetDateTime())      
    %>      
  4. Right click on your page and select View in Browser from the popup.

Your web page should display the results of your COM components GetDateTime() method. Even from this small example you should be able to see how integrating COM components into your web pages is very similar to object coding in VFP.

Conclusion

In this session you learned that VFP plays an active role in the Visual Studio family of products. In these examples you learned how to take advantage of Visual Studio with little or no work. There are other tools you should look at further these include Visual J++, The Visual Analyzer and the Visual Database tools. As we move further into the Visual Studio family you will continue to find even more added value.

About the author

Rod Paddock is president and founder of Dash Point Software, Inc. DPSI is an award winning software development company based in Seattle, WA, specializing in application development and software training. DPSI specializes in Visual FoxPro, Visual Basic, Cold Fusion, Visual Interdev SQL Server. DPSI's clients include: ADTC, SBT Accounting, The US Coast Guard, The US Navy, Pinnacle Publishing, Intel and Azalea Software. Dash Point Software, Inc. was a finalist in the 1998 Visual FoxPro Excellence Awards and 1996 Windows World Open. Rod has been a featured speaker at the 1996-1998 German FoxPro DevCons, the 1995 and 1998,1999 FoxPro Developers Conferences, and the 1995-1997 FoxTeach conferences. Rod writes for several database publications including: Data Based Advisor, Foxtalk and Dbase Advisor. Rod's books include: Visual FoxPro 6.0 Enterprise Development, and VB6 for Web Development. http://www.dashpoint.com