The TextFile device in ReportBuilder converts report output into an ASCII text file. The intent of this device is to create structured data that can be imported into another application, such as a spreadsheet. The following text file formats are supported:
▪ comma-delimited
▪ tab-delimited
▪ fixed length records
▪ custom-delimited
Because report output is essentially free-form and can contain many non-textual components, ReportBuilder provides a way for you to tightly control the format of the text file generated via this device. This control is provided by the Print to File Setup dialog (accessible from the File | Print to File Setup menu option of the report designer). This dialog is pictured below.
This dialog allows you to set the default file name, select the file format, and specify the textual components that will be saved to the file and the order they will be saved. When utilizing the TextFile device, it is mandatory that these settings are completed. If no components have been selected, then a blank text file will result.
Print directly to ASCII text file.
Once a report has been configured for ASCII text file output, the following code will generate the report directly to the file:
uses
ppTypes;
ppReport1.ShowPrintDialog := False;
ppReport1.DeviceType := dtTextFile;
ppReport1.Print;
Allow the end-user to print to ASCII text file.
The following code will give the end-user the option of printing to text when the print method is called:
uses
ppTypes;
ppReport1.AllowPrintToFile := True;
ppReport1.DeviceType := dtPrinter;
ppReport1.ShowPrintDialog := True;
ppReport1.Print;
The report component has an OnSaveText event that fires each time a textual component is saved to the text file. This event can be used to customize the output generated to the text file. An example of what can be achieved via this event is provided in demo 106 (..\Demos\Reports\dm0106.pas).