Fastreport self-organizing skills

Source: Internet
Author: User
[Formatdatetime ('Mm-dd', [ibqryshipdate. "closedate"])]
[Formatdatetime ('Mm/DD/yy', [ibqryorderform. "orderdate"])]
Total amount: [formatfloat ('######## 0.00', [totalamount])]
Order Quantity: [count (band1)]
Total Quantity: [sum ([ibqryshipdate. "quantity"])]
Marital status: [If ([ibqrypersonal. "ismarriaged"] = 1, 'yes', 'no')]
[If ([qrydata. "closedate"] = 0, '', [formatdatetime ('Mm-dd-yy', [qrydata." closedate "])]

[If ([qryprint. "curdate"] = 0, '', [formatdatetime ('Mm-dd', [qryprint." curdate "])]
[If ([qryprint. "Stype"] = '0', [ban], [Huo])]

If length (TRIM ([mainadoquery. "process name"]) mod 35 = 0 then
Begin
Bmdata. Height: = 20 * int (length (TRIM ([mainadoquery. "process name"])/35 );
Memo39.height: = 20 * int (length (TRIM ([mainadoquery. "process name"])/35 );
End
Else begin
Bmdata. Height: = 20 * (INT (length (TRIM ([mainadoquery. "process name"])/35) + 1 );
Memo39.height: = 20 * (INT (length (TRIM ([mainadoquery. "process name"])/35) + 1 );
End

Fast Report problem set

Nxyc_twz@163.com

---------------- Use a UDF ----------------------------------------

Q: How do I add my UDF?
A: Use the tfrreport. onuserfunction event. Here is a simple example:

Procedure tform1.frreport1userfunction (const name: string;
P1, P2, P3: variant; var val: variant );
Begin
If ansicomparetext ('sumtostr', name) = 0 then
VAL: = my_convertion_routine (frparser. Calc (P1 ));
End;

Then, you can use the sumtostr function anywhere in the report (any expression or script.

Q: But it only works in a tfrreport component. But do I want to use my UDF anywhere (in all the tfrreport components?
A: Use the onuserfunction event handle as the public handle of all components. If you cannot do this, you need to create a function library:

Type
Tmyfunctionlibrary = Class (tfrfunctionlibrary)
Public
Constructor create; override;
Procedure dofunction (fno: integer; P1, P2, P3: variant;
Var val: variant); override;
End;

Constructor tmyfunctionlibrary. Create;
Begin
Inherited create;
With list do
Begin
Add ('datetostr ');
Add ('sumtostr ');
End;
End;

Procedure tmyfunctionlibrary. dofunction (fno: integer; P1, P2, P3: variant;
Var val: variant );
Begin
VAL: = 0;
Case fno
0: VAL: = my_dateconvertion_routine (frparser. Calc (P1 ));
1: VAL: = my_sumconvertion_routine (frparser. Calc (P1 ));
End;
End;

To register a function library, call
Frregisterfunctionlibrary (tmyfunctionlibrary );
To uninstall the function library, call
Frunregisterfunctionlibrary (tmyfunctionlibrary );

Q: How do I add my functions to the function list (using expression builder )?
A: Use the fraddfunctiondesc process (in the fr_class unit ):

Fraddfunctiondesc (funclib, 'sumtostr', 'My Functions ',
'Sumtostr (<number>)/converts number to its verbal presentation .');

Note: The "/" symbol is required! It separates the function syntax from its description.
Funclib is declared as your own function library (you can set it to nil if you do not use the function library). When the function library is not registered, all its functions will be automatically deleted from the function list.

---------------- Use the variable -------------------------------------

Q: How can I program the filling of the Variable list (in the data dictionary )?

A: All variables and classes in the data dictionary are stored in tfrreport. dictionary. variables.

With frreport1.dictionary do
Begin
// Create a category (the name is blank)
Variables ['new category ']: = '';
// Create a variable
Variables ['new variable']: = 'mermerdata. MERs. "custno "';
Variables ['another variable']: = 'page #';
End;

Q: I have defined the string variable:

With frreport1.dictionary do
Variables ['month']: = 'march ';

But when I run the report, an error occurs. Why?

A: Because fastreport assumes that the string variable value in the data dictionary is an expression, it needs to be analyzed and computed.
You can use other methods:

With frreport1.dictionary do
Variables ['month']: = ''' + 'march' + '''';

Alternatively, use frvariables to transmit fixed data to the report.

Q: Do I not want to display certain datasets in the data dictionary?

A: Use tfrreport. dictionary. disableddatasets:

With frreport1.dictionary do
Begin
// Close the dataset
Disableddatasets. Add ('mermerdata. Bio ');
// Or close the entire data module/Form
Disableddatasets. Add ('mermerdata *');
End;

Q: How can I transfer data to a report?

A: There are several ways to implement it. The first is to use the global object frvariables (defined in the fr_class unit ):

Frvariables ['my variable']: = 10;

This Code creates a variable named "My variable" with a value of 10. This is the best way to transmit fixed data reports.

The second method is to use the tfrreport. ongetvalue event. This method can be used to transmit dynamic data and records.

Procedure tform1.frreport1getvalue (parname: string; var parvalue: variant );
Begin
If parname = 'myfield' then
Parvalue: = table1myfield. value;
End;

Finally, the third method is to define variables in the data dictionary by programming (you can refer to previous problems ):

With frreport1.dictionary do
Begin
Variables ['myvariable']: = 'mermerdata. MERs. "custno "';
Variables ['another variable']: = '10 ';
End;

Q: Can I transfer data between reports and programs?
A: Use the frvariables object. If you write the following code in the script of any object in the report:

Myvariable: = 10

In your program, you can use the following code to obtain the value of myvariable:
V: = frvariables ['myvariable'];

---------------- Script (fastreport Pascal )---------------------------------

Q: Can scripts be used in band?

A: Of course. select band and press Ctrl + enter or select the "onbeforeprint" attribute in the Object Browser.

Q: Can scripts be used on the report page?

A: Of course. Select the page (click in the blank space), and then select the "onbeforeprint" attribute in the Object Browser. If this page is a dialog box, this attribute is "onactivate ".

Q: I have two objects: memo1 and memo2. can I call the attributes and methods of memo2 IN THE memo1 script?

A: Of course, for example, you can do this: Object Name. attribute name.

Q: What attributes can I use in a script?

A: almost all the properties you can see in the Object Browser. For example, you can use font. Name and font. Size to access font attributes.

---------------- Other questions --------------------------------------------

Q: How can I change the order of one page in a multi-page report?

A: drag the tab to the target position.

Q: I want to view all the fields and variables. I want to use the list in the report to implement it?

A: Set tfrreport. mixvariablesanddbfields: = true. Now, all data fields and variables can be accessed in the "insert data field" dialog box.

Q: Do not want to display the import option dialog box?

A: Set all required options in the import component (for example, tfrtextexport), and close this dialog box by setting the showdialog attribute to false.

Q: Why does the totalpages variable not work? It always returns 0.

A: Set the two-pass option in your report. To set it, open the "Report options" dialog box in the "file" menu of the report designer.

Q: I use BLOB fields to store my reports. When I run the report designer, does it show that my report is not named?

A: Before running the report designer, do the following:

Frreport1.filename: = 'name of my report ';

Q: Do I want to redefine the "open" and "save" buttons in the report designer?

A: view the tfrdesigner component. It has several required events: onloadreport and
Onsavereport. Here is a short code example:

Procedure tform1.frdesigner1loadreport (Report: tfrreport;
VaR reportname: string; var opened: Boolean );
Begin
With myopendialog do
Begin
Opened: = showmodal = mrok;
If opened then
Begin
Report. loadfromblobfield (...);
Reportname: = ...;
End;
End;
End;

Procedure tform1.frdesigner1savereport (Report: tfrreport;
VaR reportname: string; saveas: Boolean; var saved: Boolean );
Begin
If saveas then
With mysavedialog do
Begin
Saved: = showmodal = mrok;
If saved then
Begin
Report. savetoblobfield (...);
Reportname: = ...;
End;
End
Else
Report. savetoblobfield (...);
End;

Q: In QR code, I can write the following code: qrlabel1.caption: = 'some text'. Can I use fr to do this?

A: The FR object is not a component (this is not like QR, Rb). However, you can use the tfrreport. findobject method to find the object by using the object name.

VaR
T: tfrmemoview;
Begin
T: = tfrmemoview (frreport1.findobject ('mo1 '));
If T <> nil then
T. memo. Text: = 'fastreport ';
End;

Q: Do I want to customize the hotkey in the user Preview (tfrpreview component?

A: This component has a window: tform attribute. Specify the custom handle to the window. onkeydown attribute.

Q: Fast Report 2.4 cannot load freereport 2.21 files?

A: You only need to change the first byte of the report file in hexadecimal notation, and then modify the following part in the source code. After these modifications, load the report and save it. Finally, return to the source code.

Fr_class:

Function readstring (Stream: tstream): string;
Begin
{If frversion> = 23 then}
Result: = frreadstring (Stream) {else
Result: = frreadstring22 (Stream );}
End;

Procedure readmemo (Stream: tstream; memo: tstrings );
Begin
{If frversion> = 23 then}
Frreadmemo (stream, Memo) {else
Frreadmemo22 (stream, Memo );}
End;

Fr_utils:

Procedure frreadmemo (Stream: tstream; L: tstrings );
VaR
S: string;
B: byte;
N: word;
Begin
L. Clear;
L. Text: = frreadstring (Stream); exit;
Stream. Read (n, 2 );
If n> 0 then
Repeat
Stream. Read (n, 2 );
Setlength (S, N );
Stream. Read (s [1], n );
L. Add (s );
Stream. Read (B, 1 );
Until B = 0
Else
Stream. Read (B, 1 );
End;

Function frreadstring (Stream: tstream): string;
VaR
S: string;
N: integer;
B: byte;
Begin
Stream. Read (n, 4 );
Setlength (S, N );
Stream. Read (s [1], n );
If (n> 0) and (S [N] = # $ 0a) then
Setlength (S, N-2 );
// Stream. Read (B, 1 );
Result: = s;
End;

Q: How can I print a report out of print preview?
A: Here is a piece of code:

Frreport1.preparereport;
Frreport1.printpreparedreport ('', 1, true, frall );
Or
Frreport1.printpreparedreportdlg;

Q: I want to rotate an image in a report. The problem is that this image is generated by my application. Is there a way to load this image into the report before printing?

A: Use the tfrreport. onbeforeprint event:

If view. Name = 'picture1' then
Tfrpictureview (view). Picture. loadfromfile (...) or
. Assign or
Anything you want to do
 

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.