Serialized fastreport

zhaozj2021-02-16  51

Originally developing a report plug-in, because the remote transmission is required, there is a serialization report, and the serialization of FastReport has two ways.

1. Only serialize data, accept data by the client, and present the report, this way you need to store the report format file xxx.frf on the client side.

2. Serialized FastReport's result set (ie, the FRP file that can be calculated after the data), so the FRF file does not need to exist on the client. I tend to adopt this way, after all, the more the client is, the better the client.

After opening a table, after the FR generation result is fed into FRP, it is found that there is 64K, this is not tolerated, this is just 2xx data, but this problem is very simple, compressed (only 4K), D7 There is a compressed unit Zlib, as for Zlib's usage is simple, it provides Stream and String compression method. Since this problem solved, the resolved code,

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

On the server side

FRREPORT1.DATASET: = frDbDataSet1; // Setting FRREPORT DataSet Properties frDbdataSet1.DataSet: = adoQuery1; // Link frDbdataset and dataset instance adoquery1.open; // acquisition data frReport1.loadFromFile ('d: /1.frf'); / / Load a report format file frReport1.preparereport; // execute a report, get the data, do not display frReport1.savePrePrePortReport ('D: /3.frp'); // Call the result of the report

// Load 3.FRP, you can get serialized data, but this is to access the hard disk, not cool. Take a look at the SavePreParedReport code

procedure TfrReport.SavePreparedReport (FName: String); var Stream: TFileStream; begin Stream: = TFileStream.Create (FName, fmCreate); EMFPages.SaveToStream (Stream); Stream.Free; end; In this case, to see whether it is public EMFPages It seems that it is ok, then we can finally change it.

Stream: = TmemoryStream.create; Emfpages.SaveTream (stream);

RESULT: = stream;

Client

It's simpler, you don't need any dataset, even the instance of the FREPORT class can also be generated,

WITH TFREPORT.CREATE (NIL) Do Begin Try LoadPrePrePortReport ('D: /2.frp'); // can also be changed to the form of above, using EMFPAGES SHOWPREPAREDREPORT; FINALLY FREE; END;

In this problem, you can learn several main methods of FastReport.

PrepareReport // Get the report from the data set

ShowPreParedReport // Displays reports that have been received, pay attention to the difference between ShowReport, in fact, the implementation of ShowReport is clear)

LoadPreparedReport // load a result from FRP

SavePreparedReport // Call the result into a file

LoadFromFile // Load report format file

转载请注明原文地址:https://www.9cbs.com/read-21191.html

New Post(0)