Database development and training for Birmingham and the midlands
Specialists in Microsoft Access and Visual Foxpro database training and development
I am happy to hear from existing clients but I am taking no new calls.
Using a VFP DLL in a dotNet system
If you want to migrate a Visual FoxPro system into dotNet then you will obviously have to rewrite everything in the new language, probably C# or Basic if you're sticking with Microsoft. If the FoxPro database is a large one then the rewrite will take a lot of time and effort and you will have to bring a completely new system into operation with a sudden-death changeover. Even with the best of testing this is still a risky business and one way of managing the risk is to convert some of your existing FoxPro system into a DLL that can be called from dotNet. This allows you to commission the new system in a number of stages. The first might be a database that is just a series of VB or C# forms which call VFP for data handling and business logic; subsequent stages would see the classes of the VFP DLL being replaced by native dotNet classes. The overall project might take a little longer but the user would be using the new forms for a lot of this time and the improved feedback should lead to a better final result.
Writing a VFP DLL
The functionality of the DLL must be wrapped into a class and this must be a custom class of type OLEPUBLIC. The example described below opens the Customer table and finds the name of the company for a given customer id.
The first step is to define the class and to give it a property that will hold the customer name. A real world class would of course have properties to match every field of the table:
*-- The company field is C(40) so declare a property to match.
Company = Space(40)
The DLL can't have any user interface so we can't have messages telling us what Fox is doing. We can turn these off in the Init method of the class:
*-- No user interface in a DLL so turn off messages.
Set Console Off
Set Notify Off
Set Safety Off
Set Talk Off
Set Notify Off
The DLL will have to open the customer table and set it into Cust_ID order so that we'll be able to find the customer later. The calling program will need to know whether the DLL has managed to open the table so we'll return the record count:
*-- Open the customer table.
Set Order To Cust_ID
*-- How many records are there in the table.
The SetName method of the class will take the customer ID as a parameter and look for the matching record:
*-- Set the name for this customer ID.
Local llFound As Boolean
This.Company = Customer.Company
llFound = .T.
This.Company = Space(40)
llFound = .F.
*-- Have we found anything.