Lazarus

Programming => Packages and Libraries => LazReport => Topic started by: mirce.vladimirov on December 31, 2014, 08:19:21 am

Title: howto loadfromdb ?
Post by: mirce.vladimirov on December 31, 2014, 08:19:21 am
So far I created many reports using Lazreport and all of these reports are stored in a *.lrf file on the working directory of the application that calls them.
But I think that it would be veeery good to store my *.lrf files into a database and do a frreport1.loadfromdb from within a program.
I know there is such a thing but i dont know how to use it,  how to store a report into a DB and how to load it from there.
Title: Re: howto loadfromdb ?
Post by: JZS on December 31, 2014, 09:23:36 am
1. Have your design ready and saved, for instance, as "YourReport.lrf".
2. Have a Dataset configured to read/write to your database where you intend to keep the forms in a blob field. Make sure to have at least two fields, first is Integer and the second is the blob where your report goes in.
3. For the first and one time only, you do:
Code: [Select]
  frReport1.LoadFromFile('YourReport.lrf');
  frReport1.SaveToDB(EditableDataSet, FieldNumber);
and thereafter you comment them out and use:
Code: [Select]
  //frReport1.LoadFromFile('YourReport.lrf');
  //frReport1.SaveToDB(EditableDataSet, FieldNumber);
  frReport1.LoadFromDB(DataSet, FieldNumber);


PS: FieldNumber is the first Field in your dataset and it should be an integer, where the values stored will be compared to find match, when found it reads the very second field of the matched record.
Same concept when loading.

For more details, look at SaveToDB/LoadFromDB at the source (Unit: LR_Class).

Edit:
Whenever you update the design "lrf" make sure to call SaveToDB once more to update your fields.
TinyPortal © 2005-2018