Browse DevX
Sign up for e-mail newsletters from DevX


Extending the Visual FoxPro 9 Reporting System : Page 3

In this article, you'll learn about Visual FoxPro 9's report listener concept, how it receives events as a report runs, and how you can create your own listeners to provide different types of output in addition to print and preview.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

HTML and XML Output
Because one of the design goals of the development team was to provide additional types of report output, Visual FoxPro 9 includes two subclasses of _ReportListener, called the HTMLListener, and the XMLListener, providing HTML and XML output, respectively. These listeners are built into ReportOutput.APP but are also available in _ReportListener.VCX.

Listener type 5 specifies HTML output and type 4 is for XML output, so you could just use the following command to output to HTML:

report form MyReport object type 5

However, this doesn't give you any control over the name of the file to create or other settings. Instead, call ReportOutput.APP to give you a reference to the desired listener, set the desired properties, and then tell the REPORT command to use that listener.

The following code creates an HTML file called MyReport.HTML from the MyReport report. When you specify type 5, ReportOutput.APP uses its built-in HTMLListener class to provide output.

loListener = .NULL. do (_reportoutput) with 5, loListener loListener.TargetFileName = 'MyReport.html' loListener.QuietMode = .T. report form MyReport object loListener

The following code creates an XML file called MyReport.XML from the MyReport report, containing only the data. In this case, the snippet uses the XMLListener class (type 4).

loListener = .NULL. do (_reportoutput) with 4, loListener loListener.TargetFileName = 'MyReport.xml' loListener.QuietMode = .T. loListener.XMLMode = 0 && 0 = data only, 1 = layout only, 2 = both report form MyReport object loListener

HTML output actually uses the XML listener to produce XML and then uses XSLT to produce the HTML end-result.

Both of these listener classes have additional properties you can use to further control the output. I recommend a look at the Visual FoxPro documentation for details. Also, as they are subclasses of _ReportListener, listener classes support the capabilities of the _ReportListener class, including chaining listeners and running multiple reports. Here's an example that outputs to both XML and HTML at the same time:

use _samples + 'Northwind\Orders' loListener1 = .NULL. do (_reportoutput) with 4, loListener1 loListener1.TargetFileName = 'MyReport.xml' loListener1.QuietMode = .T. loListener1.XMLMode = 0 && 0 = data only, 1 = layout only, 2 = both loListener2 = .NULL. do (_reportoutput) with 5, loListener2 loListener2.TargetFileName = 'MyReport.html' loListener2.QuietMode = .T. loListener1.Successor = loListener2 report form MyReport object loListener1

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date