FastReport FAQ

xiaoxiao2021-03-06  42

FastReport Problem Set from Delphi Garden Http://www.delphifans.com/infoview/Article_401.html

---------------- Use custom functions --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------

Q: How do I add my custom function?

A: Use the TFRREPORT.ONUSERFUNCTION event. There is a simple example here:

Procedure TFORM1.FRREPORT1USERFUNCTION (const name: String;

P1, P2, P3: Variant; Var: 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 can only work in a TFRREPORT component. Can I want my custom function to use anywhere (in all TFRREPORT components)?

A: Make the ONUserFunction Event handle as a common handle of all components. If you can't do this, you need to create a log library:

Type

TMYFUNCTIONLIBRARY = Class (TFRFunctionLibrary)

public

CONSTRUCTOR CRETE; 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 of

0: Val: = my_dateconvertion_routine (frParser.calc (p1));

1: Val: = my_sumconvertion_routine (frParser.calc (p1));

END;

END;

To register a library, call

FrregisterFunctionLibrary (TMYFUNCTIONLIBRARY);

To unload the function library, call

FrunRegisterFunctionLibrary (TMYFUNCTIONLIBRARY);

Q: How do I add my function to the function list (with an expression generator)?

A: Using the FradDfunctionDesc process (in the fr_class unit):

FradDfunctionDesc (Funclib, 'SUMTOSTR', 'My Functions ",

'SUMTOSTR () / Converts Number To ITS Verbal Presentation.');

Note: "/" The symbol is a must! It divides the function syntax from its description.

FunClib is declared as your own library (if you don't use the function library to set it to nil). When the function library is not registered, all its functions will automatically remove from the function list.

---------------- Use the variable ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----- q: How do I program to implement the population variable list (in the data dictionary)?

A: All variables and categories in the data dictionary are stored in TFRREPORT.DICTIONARY.VARIABLES.

With frReport1.dictionary do

Begin

// Create a classification (name is blank)

Variables ['new category']: = '';

// Create a variable

Variables ['new variable']: = 'CustomerData.customers. "Custno";

Variables ['Another Variable']: = 'Page #';

END;

Q: I define the string variable:

With frReport1.dictionary do

Variables ['Month']: = 'march';

But when I run a report, there is a mistake, why?

A: Because FastReport assumes that the string variable value in the data dictionary is an expression, it needs to be analyzed, calculate it.

Other methods can be used:

With frReport1.dictionary do

Variables ['Month']: = '' '' 'March' '' ';

Alternatively, use frVariables to transfer fixed data to the report.

Q: I don't want to display certain data sets in the data dictionary?

A: Use tfrreport.dictionary.disabledDataSets:

With frReport1.dictionary do

Begin

// Close this data set

DisabledDataSets.Add ('CustomerData.bio');

/ /, Turn off the entire data module / form

DisabledDataSets.Add ('CustomerData *');

END;

Q: How do I transfer the data to the report?

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

Frvariables ['My Variable']: = 10;

This code created a variable name "My Variable" and a value of 10. This is the best way to transfer fixed data.

The second method is to use TFRREPORT.ONGETVALUE events. This can use this method to transmit dynamic data, record, etc.

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 a data dictionary (can refer to the previous problem):

With frReport1.dictionary do

Begin

Variables ['myvariable']: = 'CustomerData.customers. "Custno";

Variables ['Another Variable']: = '10';

END;

Q: Can I transfer data between reports and programs?

A: Using the Frvariables object. If you write the following code in the script of any object of the report:

Myvariable: = 10

So, in your program, you can use the following code to get the value of MyVariable:

v: = frvariables ['myvariable'];

------------------------------------------- ---- Q: Can you use a script in BAN?

A: Of course. Select Band, then press Ctrl Enter or select the "OnBeforePrint" property in the object browser.

Q: Can I use a script in the report page?

A: Of course. Select a page (click on the blank) and select the "OnBeforePrint" property in the Object Browser. If this page is a dialog form, then this property is "onactivate".

Q: I have two objects: MEMO1 and MEMO2. Can I call MEMO2 properties and methods in MEMO1 scripts?

A: Of course, for example, you can do this: object name. Property name.

Q: In the script, which attributes I can use?

A: Almost all the properties you can see in the object browser. For example, you can use font.name, font.size, etc. to access the font properties.

---------------- other questions-------------------------------- ----------------

Q: How to change the order of a page in a multi-page report?

A: Drag the page label to the destination location.

Q: I want to see all 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.

Q: I don't want to display the Guide option dialog?

A: Set all the required options in the import component (such as tfrtextexport) and then close this dialog by setting the showdialog property to false.

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

A: Set the Two-Pass option in your report. To set it, you need to open the Report Options dialog in the File menu of the Report Designer.

Q: I use the BLOB field to store my report. When I run a report designer, it shows that my report is not named?

A: Before running the report designer, do this:

FRREPORT1.FILENAME: = 'Name of My Report';

Q: I want to redefine the "Open" and "Save" button in the Report Designer?

A: View the TFRDesigner component. It has several required events: OnloadReport and

OnsaveReport. There is a small code example:

Procedure TFORM1.FRDESIGNER1LOADREPORT (Report: TFRREPORT)

Var ReportName: String; Var Opened: Boolean;

Begin

With myopendialog do

Begin

Opened: = showmodal = mrok

If opened kil

Begin

Report.LoadFromBlobfield (...);

Reportname: = ...;

END;

END;

END;

Procedure TFORM1.FRDESIGNER1SAVEREPORT (Report: TFRREPORT)

Var ReportName: String; Saveas: Boolean; Var Saved: Boolean;

Begin

IF saveas the

With mysavedialog do

Begin

Saved: = showModal = mrok

If Saved Then

Begin

Report.savetoblobfield (...);

Reportname: = ...;

END;

end

Else

Report.savetoblobfield (...);

END;

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

A: FR object is not a component (this is not like QR, RB). But use the TFRREPORT.FINDOBJECT method to find the object with the object name.

VAR

T: tfrmemoview;

Begin

T: = tfrmemoview (FRREPORT1.FINDOBJECT ('MEMO1'));

IF t <> nil dam

T.Memo.text: = 'fastreport';

END;

Q: I want to customize the hotkey in the user preview (TFRPREVIEW component)?

A: This component has a window: TFORM properties. Specify the custom handle to the Window.onkeyDown property.

Q: Fast Report 2.4 Cannot load the FreeReport 2.21 file?

A: This only needs to use a 16-en-number to change the first byte of the report file, and then modify the part below in the source code. After these modifications, the report is loaded and saved 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

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

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 do I not print the report in the print preview?

A: Here is a code:

FRREPORT1.PREPAREREPORT;

FRREPORT1.PRINTPREPAREDREPORT ('', 1, true, frall);

or

FRREPORT1.PRINTPREPAREDREPORTDLG;

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

A: Using TFRREPORT.ONBEFOREPRINT events:

if View.name = 'Picture1' Then

TFRPICTUREVIEW (View) .Picture.loadFromFile (...) or

.Ssign or

Anything you want to do

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

New Post(0)