How To…Load Report Templates from a Database

Question

“How do I load report templates from a database?”

Solution

Reports can be saved to a database at design-time or run-time.

  1. First, create a database table that contains a BLOB field for storing the templates and a string field for storing the name of the templates:For this example let’s create a table called reports
     Reports
     Name char(40)
     Template blob
  2. Use a DataSet, DataSource, DBPipeline to connect to the reports table.
  3. Bind the Report.Template to the database by setting the required properties.  This can be done by using the Object Inspector or via Delphi code
    uses
      ppTypes;
     
    begin
    
      // set storage type
      ppReport1.Template.SaveTo := stDatabase;  
    
      // connect to datapipeline
      ppReport1.Template.DatabaseSettings.DataPipeline  := plReports; 
      ppReport1.Template.DatabaseSettings.NameField     := 'Name'; 
      ppReport1.Template.DatabaseSettings.TemplateField := 'Template';
    
    end;

     

  4. Load and Save a reports a. Use the Designer File | Open and Save options.b. Use Code
      ppReport1.Template.DatabaseSettings.Name := 'myTestReport' 
    
      ppReport1.Template.SaveToDatabase;
      ppReport1.Template.LoadFromDatabase;