Question
“How do I load report templates from a database?”
Solution
Reports can be saved to a database at design-time or run-time.
- 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 - Use a DataSet, DataSource, DBPipeline to connect to the reports table.
- 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
1234567891011121314usesppTypes;begin// set storage typeppReport1.Template.SaveTo := stDatabase;// connect to datapipelineppReport1.Template.DatabaseSettings.DataPipeline := plReports;ppReport1.Template.DatabaseSettings.NameField := 'Name';ppReport1.Template.DatabaseSettings.TemplateField := 'Template';end;
- Load and Save a reports a. Use the Designer File | Open and Save options.b. Use Code
1234ppReport1.Template.DatabaseSettings.Name := 'myTestReport'ppReport1.Template.SaveToDatabase;ppReport1.Template.LoadFromDatabase;