Ga naar inhoud

Architecture

Reporting architecture

Synopsis

Reports are stored in the database. Each report has a unique name, and is associated with a form in the application. When opening a form, a list of report names for that form is loaded.

SQL

Table definition for reports:

CREATE TABLE "REPORTDEFS" (
    "ID" INT NOT NULL,
    "Name" NVARCHAR(200) NOT NULL,
    "Form" NVARCHAR(200) NOT NULL,
    "Description" NTEXT NULL,
    "Data" NTEXT NOT NULL,
    "Design" NTEXT NOT NULL,
        "Hidden" BOOL NOT NULL,
    PRIMARY KEY ("ID")
);
CREATE UNIQUE INDEX "U_REPORTNAME" ON REPORTDEFS(Name);
Here: * Name is the unique name of the report. * Form is the form in which the report is shown. * Description A textual Description * Data the data description of the report. * Design The FastReport design of the report. * Hidden means the report is available in a form, but is not accessible through the print button.

Report data

Report data is a structure that is used to describe the report. It consists of: 1. 1 or more named SQL statements. These have the following properties: * Name (string) Must be unique in the report. * SQL (string) SQL statement to execute. * Description (string) optional description. * Master (string) Optional name of master dataset.

  1. 0 or more report parameters. A report parameter has 3 properties:
  2. A unique name.
  3. A data type (string, integer, float, datetime, boolean )
  4. A default value.

The SQL statement can have parameters, as per the usual delphi convention Select A,B,C from D where (E=:Param) these parameters must be in the list of report parameters.

Additionally, it can have macros:

{Name}
Which can be used to insert arbitrary text in the SQL statement.

Printing interface in forms:

A protected call PrintReport exists to print a report:

Procedure PrintReport(ReportName : String; Params : TReportParams)
Where TReportParams is a list of TReportParam:
TReportParam = record
  Name : String;
  Value : String;
end;  
This will fetch the report definition in the database, will create the data, substituting first macros and then parameters in the SQL statement. It also sets up any master-detail relations.

The TReportParams list has additional methods to easily add Parameters, corresponding to the data types.

Procedure Add(Const aName : String; AValue : String);
Procedure Add(Const aName : String; AValue : Integer);
Procedure Add(Const aName : String; AValue : Double);
Procedure Add(Const aName : String; AValue : TDateTime);
Procedure Add(Const aName : String; AValue : Boolean);
They add a record to the list, with the value parameter formatted correctly.

A public method exists

Procedure PrintReport(ReportName : String; Direct : Boolean = False);
This method is called by the print button. If Direct is true, the preview is skipped, and the report is sent to the default printer.

It will call the following virtual protected method to get the parameter list:

Procedure GetReportParameters(Const ReportName : String; aList : TReportParams);

Every form overrides this method to deliver the correct parameters to the report. Report printing can be halted at this point by raising an exception.

System Parameters.

Some special parameters exist:

  __name__
These are applied to the printer settings.
__Copies__
For example will set the number of copies.

Development:

The standard forms are developed and stored in files, checked in in the version system. They are uploaded to the database using a separate tool or in the program itself. * Easier to maintain * Allows to send a new version which can be read into the database.