How Can the VFP Toolkit Help?
For VFP developers, the benefits from the VFP Toolkit should be obvious. The set of classes in the toolkit will help you get up to speed immediately, effectively using the same set of functions familiar to Visual FoxPro developers. Obviously, this should not be considered a replacement for similar functions already in Visual Studio .NET; in fact, the toolkit help file states if a "method maps directly to existing functionality in the .NET, use the code listed in the Implementation section of the help detail instead." Hence, the "training wheels" comparison is very close; as you become more and more familiar with the contents of VB.NET or C#, you can easily switch from VFP functions to .NET functions in many cases.
As you can see from the table, however, more than half of the functions in the toolkit are totally new for Visual Studio .NET developers. The purposes behind most of them can be gleaned from their titles (see the CHM file for full descriptions and parameters) and, considering this is a free set of classes, as you review the function list I'm sure you will agree that many could be very useful. As with native Visual Studio .NET functions, some of the ones in the VFP Toolkit are overloaded; fortunately, IntelliSense will kick in when you need some coaching, and there is an XML dynamic help file included with the toolkit.
Using the VFP Toolkit
As mentioned earlier, the VFP Toolkit comes with an installation batch file. Once registered, you can begin using the VFP Toolkit like any other .NET assembly. To incorporate the toolkit into your application right-click on the References tab in the Solution Explorer and click Add Reference. If the DLL was registered properly, you should see an entry for it under the .NET tab of the Add Reference dialog box (look for the Visual FoxPro Toolkit for .NET entry in the References list). If you don't see the toolkit, click Browse, locate and select the DLL, and then click Open. This adds the toolkit to the Selected Components section of the Add Reference dialog box. Click OK and you are ready for the next step, which is to add the namespace to your code.
Now that you have added a reference to the toolkit, you can begin using it in your applications. In order to use the toolkit you need recognize some fundamental differences between VB.NET and C#. For VB.NET, you have two options: the first is to add toolkit classes through the Solution Explorer. To do this, right-click on your project and click Properties to display the Property Pages dialog box. Then, click the Imports option under Common Properties. Type the name of each class you want to include in your project into the Namespace box, and then click Add Import.
The other option is to do it directly in code (remember, there's code for everything in .NET!). Add it to the top of your class or form, like this:
For C# developers, there are no dialog boxes; you'll have to add the namespace in code (but hey, you're a C# developer, who needs dialog boxes anyway?) You can either include the entire assembly:
Or include only selected classes:
using VfpData = VFPToolkit.vfpData;
using VfpStrings = VFPToolkit.strings;
To illustrate how to use VFP Toolkit functions in your project, I've constructed a simple Windows form in VB.NET that uses three of the many functions available: GetWordCount(), which counts the number of words in a string; Lower(), which is a redirection function to change a string to lower-case; and Browse(), which displays a form with data from a table. Figure 1 shows the form itself.
|Figure 1: A sample form with controls that use three of the VFP Toolkit functions.|
shows the form launched by the Browse
button. Listing 1
provides the code behind the sample form. For simplicity, I removed the Windows form designer code from Listing 1
|Figure 2: The "Browse" function, triggered by a button on the sample form, launches a separate form to show the data. This form is included in the toolkit.|
The C# code is somewhat similar, as shown in Listing 2. Again, I removed the Windows form code.
|Considering how much work has been done for you, and the fact that this is public domain software, the toolkit is a steal for what it provides.|
These are simplistic examples, but I hope they are enough to get you interested in checking out the VFP Toolkit. Considering how much work has been done for you, and the fact that this is public domain software, the toolkit is a steal for what it provides. For example, Listing 3
shows the code behind the GetWordCount function (in C#).
Have another look at the table of toolkit functions and I think you will appreciate what this set of classes can bring to your application. Imagine trying to code all of those from scratch on your own.
Under the Hood of the VFP Toolkit
The VFP Toolkit classes are built into what is called an assembly. In Visual Studio .NET, assemblies provide flexibility when dealing with issues like security, version control (including side-by-side execution of differing versions) and debugging. Assemblies are the basic building blocks of a remotely deployable application, as only the ones required for startup need to be present for the application to run. Any other required assemblies are retrieved on demand, which keeps the initial deployment costs low.
The VFP Toolkit is an example of a static assembly. A static assembly is one that is already defined and contains all of the resources it may require (bitmaps, JPEGs, resource files, etc.). .NET can also construct dynamic assemblies, which are built at run-time and can be saved to disk after execution.
Assemblies can also have various compositions. VB.NET and C# projects can be compiled into single-file assemblies (where the code module has a single entry point) or as library assemblies. Library assemblies, like class libraries, have components (types) that can be called by other assemblies, but have no entry point.
Assemblies can also be constructed as multi-file assemblies. This is useful if you have multiple code modules under development by different developers, written in different languages, or you need to construct an application that can be downloaded via the <object> tag in IE. Multi-file assemblies must be compiled using the command-line compilers or Visual Studio .NET with the Managed Extensions for C++.
At a minimum, an assembly must contain type information and implementation (class definitions and the code that goes with them) as well as an assembly manifest. This is the metadata that describes how the elements of an assembly relate to each other. An assembly manifest contains the assembly name, its version number, culture (language-specific information, and only required when building satellite assemblies), strong name information (public key information from the publisher, if given a strong name), a list of files in the assembly, type reference information and information on referenced assemblies. An example of this information is in the AssemblyInfo.cs portion of the VFPToolKitNet_CSharpNET_Source project, a portion of which is reproduced here:
("Visual FoxPro Toolkit for .NET")]
("Visual FoxPro Toolkit for .NET")]
("Team: Kamal Patel, Cathi Gero, " +
Rick Hodder, Nancy Folsom, Ken Levy")]
("Visual FoxPro Toolkit for .NET")]
("Public Domain (none)")]
The command-line compilers for creating an assembly are fairly straightforward. Once you are ready to turn a module into an assembly, execute the following for a single-file assembly:
<compiler command> /out:<file name> <module name>
Or the following for a library assembly:
<compiler command> /t:library <module name>
So to create a library assembly from a VB.NET module, you execute this:
vbc /out:myCodeLibrary.dll /t:library myCode.vb
For more information on assemblies, refer to the Visual Studio .NET help.
A Great Set of Tools for a Great Price
For VFP developers and anyone else wanting to learn .NET and add functionality to their developmental toolbox, the VFP Toolkit is a great resource. Again, this is public domain software, which you can download from GotDotNet. Check it out, and I think you'll agree that this is a must-have set of classes for your application.
The VFP section of the GotDotNet site has much more information for Visual FoxPro developers looking to expand their knowledge of Visual Studio .NET. In addition to the VFP Toolkit, there are several white papers regarding COM Interop, XML Web services and .NET Interop within VFP applications (to name a few).