Examples Delphi

Title: The manager of reports
Question: Reports generator FastReport has a remarkable capability of changing the documents templates during the execution of the program. Using this opportunity, the programmer can not only speed up the development of the program, but also strongly simplify the further support of the program both for himself and the end user of the program. How is this opportunity normally used?
Answer:
If, for example, there are twenty reports used in the program, most likely, there also will be twenty Print Report buttons, as well as twenty Reports Design buttons (if the programmer isnt lazy or if the customer demands it) And what if the users not only need to change the already existing reports, but also to add a couple of new ones? The answer to this question is obvious- you need to create the manager of reports. How will such manager of reports help you?
It will allow you to dynamically add, change and delete reports. So let us now start creating the reports manager. To those of you, who are well familiar with FastReport, the idea is clear, and to the rest of you I will describe the details.
So, let us start from the beginning. Our reports should be stored somewhere, and for that purpose we are going to need a table. For every one of the reports we will need the following information: the name of the report, a link to the FastReport documents template or the template itself. In the example shown, there is a table in format Paradox, where all this is roughly realized. After this, it will be necessary "to draw" a manager of reports window.
Control elements can be divided in two groups. The first group is for adding new reports, changing and removing reports. The second group is for previewing the reports, printing reports and cancellations.
A new report is only an insert of a new record in the table.
A code for changing the report look like this:
//====================================
frReport1.LoadFromBlobField(taReportREPORT);
frReport1.DesignReport;
//====================================
It is as simple as it gets.
To remove a report you just remove the records from a database.
Previewing:
//====================================
frReport1.LoadFromBlobField(taReportREPORT);
frReport1.ShowReport;
//====================================
Printing without the preview.
//====================================
frReport1.LoadFromBlobField(taReportREPORT);
frReport1.PrintPreparedReportDlg;
//====================================
Function PrintPreparedReportDlg right away shows the printing dialog (if you are not aware). You can add buttons for instantly printing one, two, three or more copies. Then the code will look like this:
//====================================
frReport1.LoadFromBlobField(taReportREPORT);
frReport1. PrintPreparedReport('',Qnt, True, frAll);
//====================================

Where "Qnt" is the quantity of copies.
Due to the report templates being stored in Blob fields of the table, instead of files, it is necessary to hook up the event handler to the OnSaveReport event of the TfrDesigner object for saving the report template from the designer to the Blob field.
//====================================
taReport.edit;
frReport1.SaveToBlobField(taReportREPORT);
taReport.post;
//====================================
It is possible to hook up an event handler to the OnLoadReport event, but you will have to do it on your own. The next necessary procedure is the Report Manager call.
//====================================
procedure TfrManage.PrintDoc(DocumentName: string;FormName: string);
begin
frManage := TfrManage.create(Application);
frManage.DocumentName := DocumentName;
frManage.FormName := FormName;
frManage.showmodal;
frManage.release;
end;
//====================================
DocumentName is the name of the document by default (it is possible to substitute, for example, Form.caption to avoid writing it again.) FormName is the section of reports, necessary for each window to have its own list of documents (it is possible to substitute, for example, Form.name.)
It is also necessary to provide a way to fill in TfrDBDataSet objects. It is really easy to do that, for example, you can create two objects of that type and pass DataSource for them in the PrintDoc call.
If you have any questions, please write at mailto:vtl@msx.ru?subject=FastReport: the manager of reports.
Vitaly Kubekin for Delphi Plus (www.delphiplus.org)