TechTricks
Technical answers from the trenches 
 
 
 
 

     
   
Using a Report to Print a Single Record
 
   
 Posted: 17 August 2000
 
   
 
 Applies to: Paradox 9.0
 
   
 
Audience: Intermediate
 
       
   

Introduction

Paradox reports are great at printing entire datasets; however, they don't handle individual records well. Sure, you can use filters, but they're slow. You could also use File | Print to print the form itself, but that doesn't generally yield professional looking results.

A better approach leverages a report's strength, e.g. its ability to print an entire table. Use queries or other approaches to extract the the record(s) you want to print to a temporary table and then open the report using the temporary table as its master table.

The following code shows one way to do this:

var
   roi  ReportOpenInfo  ; parameters for the report.
   rpt  Report          ; the report itself
   tc   tCursor         ; used to capture the current record
endVar

   tc.attach( keyField )
   tc.setRange( KeyField.Value, KeyField.Value );
   tc.instantiateView( ":PRIV:ANSWER" )

   roi.Name = "MYREPORT"
   roi.MasterTable = ":PRIV:ANSWER"

   rpt.open( roi )

In this example, we assume that the table has a single field primary key called KeyField and that the form contains a field object bound to that field. The code attaches a tCursor to that field object, sets a range on the value of the field object, and then saves the resulting record to an Answer table.

This effectively performs the same thing as a QBE query with checkmarks in all fields and the key field's value as the selection criteria. It also uses an index-based approach to select the target record, which can provide an enormous performance improvement when compared to other techniques. (Currently, it's unclear whether QBE queries use indexes.)

Note: The performance benefit depends on your specific circumstances and will be discussed in detail in a future article.

The roi variable is a ReportOpenInfo variable that defines parameters for the report. It defines the name of the report and, in this case, the table to use as the report's master table (Answer).

When you run this example, your report appears in a standard Preview window, which you can use to print the report.

If you wish to print the report directly, use something like this:

var
   rpi  ReportPrintInfo  ; parameters for the report.
   rpt  Report           ; the report itself
   tc   tCursor          ; used to capture the current record
endVar

   tc.attach( keyField )
   tc.setRange( KeyField.Value, KeyField.Value );
   tc.instantiateView( ":PRIV:ANSWER" )

   rpi.Name = "MYREPORT"
   rpi.MasterTable = ":PRIV:ANSWER"

   rpt.print( rpi )

This does precisely the same thing except it prints the report without user intervention.

Tip: This approach also shows how to print reports without the Print dialog appearing. Those using sendKeys() to automatically accept the Print dialog may wish to consider replacing that code with the reportPrintInfo approach shown above.

 

       

Top

Feedback About Paradox Delphi Assorted Web Stuff
 
 
Copyright © 2000-2004, techtricks.com; All Rights Reserved.
Acknowledgements, Disclaimers, Terms and Conditions.
Article last updated on 31 May 2003

 

Other Sites: Paradox, Delphi, Perl, Web Stuff, and More


 

[- End -]