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.
Testing a VFP DLL
A DLL can't run by itself and you can only test it by making a call to the DLL. It's easiest to start by calling the class from within FoxPro itself. This will make sure that there are no internal errors of logic. Before doing that though we'll need to be able to handle the errors in the FoxPro code.
A DLL cannot have any user interface. If the DLL tries to produce any form of output you'll get an error 2031 "User-interface operation not allowed at this time". This of course includes any error message so the DLL must have comprehensive error-handling. Debugging becomes impossible if all error messages are suppressed so my own preference is to trap every error and to write details to a text file.
The Error method of the class will run whenever there is an error in the class and this code will write the basic details of the error to a text file:
Lparameters nError, cMethod, nLine
*-- Build the strings for the text file.
lcMarker = Replicate("-", 35)
lcTimeStamp = "Error at …..:" + Ttoc(Datetime())
lcLine = "Line ………:" + Alltrim(Str(nLine, 6, 0))
lcError = "Error ……..:" + Alltrim(Str(nError, 6, 0))
lcMethod = "Method …….:" + cMethod
Set Textmerge On
Set Textmerge To c:\Error.txt Additive
Set Textmerge To
Set Textmerge Off
I'm using TextMerge to add lines to the error log. Note that the lines within the TextMerge aren't indented. If they were then the indents would be output to the text file too. The code above generates error log entries looking like this:
Error at .....:19/11/10 11:56:46
With a bit more work you can use the Program() function to loop through the call stack and show how the program reached the error.
Testing the class from VFP
A simple program can create the class and call the two methods:
Local loCust As Customer
Close Databases All
Set Procedure To Customer.prg
loCust = Createobject("customer")
lcCustID = INPUTBOX("Enter customer ID")
Messagebox("Cannot find " + lcCustID)
Run the program with a known customer ID such as "RANCH" and with one that doesn't exist. Edit the text of customer.prg with a silly syntax error to make sure that the error will be detected - I used SET SAFELY ON.