Use fastreport 3.0 or a later version to create a dynamic report

Source: Internet
Author: User
1. The generated report is saved to the stream and then retrieved from the stream.
Tfrxreport. previewpages. savetostream (tstream );
Tfrxreport. previewpages. loadfromstream (tstream );

2. Add the variable to the report.
With frxreport1 do
Begin
With variables do
Begin
Category: = add;
Category. Name: = ''+ 'custom variable 1'; // note !! The first ''contains a space !! CATEGORY cannot be correctly added without spaces
With add do name: = ''+ 'custom variable 2'; // simpler format
Addvariable ('custom variable 1', 'variable 11', quotedstr ('capitalized amount '));
Addvariable ('custom variable 1', 'variable 12', quotedstr ('capitalized amount '));
Addvariable ('custom variable 1', 'variable 13', quotedstr ('capitalized amount '));
Addvariable ('custom variable 2', 'variable 21', 1880 );
Addvariable ('custom variable 2', 'variable 22', quotedstr ('capitalized amount '));
Addvariable ('custom variable 2', 'variable 23', quotedstr ('capitalized amount '));
End;
End;

3. Add a dataset dynamically. Pay attention to it !!!!!
Before obtaining the report format, set the DataSet object so that after the report control retrieves the format file,
When you place a report object, you can get the data object. If the operation order is reversed, the report object will not be able
When you get the data object, the error "no dataset" is generated when you preview the data !!
VaR
Tmpdataset: T dataset;
Datasource: tdatasource;
Frxdbdataset: tfrxdbdataset;
Begin
Tmpdataset: = T dataset. Create (Self );
Datasource: = tdatasource. Create (Self );
Frxdbdataset: = tfrxdbdataset. Create (Self );

Datasource. Dataset: = tmpdataset;
Frxdbdataset. datasource: = datasource;
// Frxdbdataset. Dataset: = tmpdataset; // This statement is available with the previous one. I do not know the difference.
Frxdbdataset. Username: = 'data item name'; // Chinese name can be used.
Frxreport1.datasets. Add (frxdbdataset );
------------- Note: the program of the preceding statements must be completed before the report format is loadfromfile or loadfromstream !!!!

4. save the Report Settings data to the stream. You only need to set tfrxdesigner. onsavereport is enough, but I don't know how this item is connected to the report. I just need to put a control on the interface and it will be OK. It's weird, but it's pretty cool.

5. Custom preview window
You can reference frxpreview to create an inheritance class tfrxpreview, and then add your own features to the inherited class. This is the most time-consuming.

6. Principles of processing order (truth): assume that the report template is stored in the database.
A. You must inject the table object into the data before extracting the report template. Otherwise, an error is reported during preview.
B. The dynamic variables must be extracted from the Report Template before being added to the report. Otherwise, the variables do not exist.
These two sequences must be understood in the creed. For the reason, I have no time to read the source code of fastreport ~~, These two processing mechanisms were discovered after N failures.

7. add custom functions
A. Create your own function. It can be a member function of the class (Be sure to instantiate the class) or a global function.
B. Use tfrxreport. addfunction to add the function to the registration item. Note that it must be a complete definition of the function. For example, your function is:
Function myfunction (para0: Float): string;
The addfunction format is as follows:
Frxreport1.addfunction ('function myfunction (para0: Float): string', 'udf ','');
C. The return value of the function must be processed in tfrxreport. onuserfunction. Otherwise, no return value is returned even if the written format is correct in the report.

8. Use objects in reports in user-defined functions
A. Create a UDF

Function tform1.getcrossobject (crossobj: tfrxcustomcrosview): string;
Begin
// Retrieve Data Object
Result: = 'row: '+ inttostr (crossobj. matrix. rowcount );
End;

B. register the function. You can register it at form1.create.

With frxreport1 do
Begin
Addfunction ('function getcrossobject (crossobj: tfrxcustomcrosview): string ',
'Extended function ','');
End;

C. The return value of the function must be processed in tfrxreport. onuserfunction.

Function tform1.frxreport1userfunction (const methodname: string;
VaR Params: variant): variant;
Begin
If uppercase (methodname) = uppercase ('getcrossobject ') then
Result: = getcrossobject (tfrxcustomcrosview (INTEGER (Params [0]); // type conversion can be compiled
End;

 

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.