Serialization of fastreport, important tips to avoid detours

Source: Internet
Author: User

A report plug-in was originally developed. Because remote transmission is required, you need to serialize the report. fastreport can be serialized in two ways,

1. Only serialize the data. The client receives the data and presents the report. In this way, the report format file XXX. FRF needs to be stored on the client,

2. serialize the result set of fastreport (that is, the FRP file that can be saved after data is obtained), so that the FRF file does not need to exist on the client. I prefer this method. After all, the lighter the client, the better.

After opening a table and saving the results generated by Fr into FRP, we found that the size of a table is 64 KB, which is intolerable. This is only 2XX data, but the solution to this problem is also very simple, after compression (only 4 K), the D7 comes with a compression unit zlib. zlib is easy to use and provides stream and string compression methods. I will not talk about it here. Since this problem is solved, serialization is left.Code,

The serialization process is very simple. After learning several important methods of FR, it is very simple. The results are as follows:

On the server side

Frxreport1.dataset:=Frdbdataset1;// Set the dataset attribute of frreport
Frdbdataset1.dataset:=Adoquery1;// Link frdbdataset and dataset instances
Adoquery1.open;// Retrieve Data
Frxreport1.loadfromfile ('D: \ 1.frf');// Load a Report Format File
Frxreport1.preparereport;// Execute the report and obtain the data, which is not displayed.
Frxreport1.savepreparedreport ('D: \ 3.frp');//Save the report result as a file

// Load 3.frpto get the serialized data, but it is uncomfortable to access the hard disk.Savepreparedreport code

Procedure Tfrxreport. savepreparedreport (fname: string );
VaR  
Stream: tfilestream;
Begin  
Stream:= Tfilestream. Create (fname, fmcreate );
Emfpages. savetostream (Stream );
Stream. Free;
End;


Now let's take a look.Whether emfpages is public or not. It seems yes, so we can change it

Stream : = Tmemorystream.Create; 
Emfpages.Savetostream(Stream);
Result: = stream;

Client

Simpler, you don't need any datasets, and even frreport instances can be dynamically generated,

WithTfrxreport. Create (Nil)Do  
Begin  
Try
Loadpreparedreport ('D: \ 2.frp');// You can also change it to the above stream format, with emfpages
Showpreparedreport;
Finally
Free;
End ;
End ;

In solving this problem, you can learn the main methods of fastreport.

Preparereport // get the report data from the dataset

Showpreparedreport // display the report with the obtained data. Pay attention to the difference with showreport. In fact, you can see the showreport implementation)

Loadpreparedreport // load a result from FRP

Savepreparedreport // Save the result as a file

Loadfromfile // load the Report Format File

note: savepreparedreport and direct reference of loadpreparedreport, previewpages is required. savetofile and previewpages. loadfromfile to replace

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.