Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReportListener - Can I use this to trap errors

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have an application which generates a range of VFP 9.0 report from a .dbf file. Brief explanation :

I have a report layout e.g. ANMREP.frx which is designed to produce a report based on 2 tables ANMHead and ANMDetl.

My application reads a table, e.g. Myinvoice.dbf. Determines that this uses format ANMrep.frx. It builds up the tables ANMHead and ANMDetl with the fields which it knows are required by ANMREP.frx and calls REPORT FORM.
(The .frx file was developed based on the same sort of data that MyInvoice.dbf contains).

This normally works fine. However if Myinvoice.dbf does not contain all the fields which the report wants to print (maybe it was produced by an earlier version of the program), there is a run-time error from the VFP reporter, correctly saying something like "Variable Add2 not found".

This error is meaningful to me, the developer, but not so meaningful to an end-user, and I would like to trap the error and give a message (at least mentioning where in my program - the REPORT FORM command - it is failing).

Can I do this with ReportListener ? I have tried to get to grips with this via an article by Doug Hennig, which I sadly found rather obscure - the very first instruction in his example fails :

loListener = createobject('MyReportListener')
report form MyReport object MyReportListener

I appreciate I am starting from a position of great ignorance but would appreciate guidance. Thanks. AM
 
Andrew,

I would think the easiest way to solve this problem would be to error-trap the REPORT FORM command.

Something like this:

Code:
lcMessage = ""
TRY
  REPORT FORM ANMRep
CATCH TO loError
  lcMessage = loError.Message
ENDTRY

IF NOT EMPTY(lcMessage)
  MESSAGEBOX(lcMessage)
    && or whatever other action you want to perform
ENDIF

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks Dave Summers

Grateful for your suggestion. I had certainly thought of examining the .frx file to see whether it contained fields which the particular document (myinvoice.dbf) is not providing.

It is possible, because you can hack into the .frx file as a .dbf file and examine records with objtype = 8, but it would be quite complicated to parse the expressions to find the field names and check whether they were being provided as part of the tables when I invoke REPORT FORM. So it is probably easier to let the error happen and to trap it.

Andrew M.
 
Thanks Mike; that works fine. I had always been nervous of using TRY . . . ENDTRY but can see how this lets the developer intercept (and expand on) the standard error messages from VFP.
 
Can I do this with ReportListener ? I have tried to get to grips with this via an article by Doug Hennig, which I sadly found rather obscure - the very first instruction in his example fails :

loListener = createobject('MyReportListener')
report form MyReport object MyReportListener

I don't know which article you're looking at, so can't give you specifics. But this looks like a generic example, not a specific one. That is, you have to substitute the name of your report listener class for "MyReportListener" and your report for "MyReport."

Tamar
 
Thanks Tamar, I had actually suspected that the sample code Extending the Visual FoxPro 9 Reporting System in Code magazine 2004 did depend on some other code. I only started with Doug’s article, because that came up on a search and he is a respected VFP figure. I suppose the name myreportlistener gives one a clue that preparatory work needs to be done !

In fact the TRY . . . ENDTRY technique works in this case, but grateful for your very prompt response

Andrew M.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top