Fast Report Problem Set

zhaozj2021-02-16  41

Fast Report Problem Set

nxyc_twz@163.com

---------------- Use custom functions --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------- q: How do I add my custom function? A: Use TFRREPORT.OnUserFunction event. There is a simple example: Procedure TForm1.Frreport1UserFunction (const name: string; p1, p2, P3: Variant; var val: variant; beginif answertext ('SUMTOSTR', NAME) = 0 ThenVal: = my_convertion_routine (frParser.calc (p1)); END; then you can be reported (any expression or script) Any place to use the SUMTOSTR function. 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:

typeTMyFunctionLibrary = class (TfrFunctionLibrary) publicconstructor Create; override; procedure DoFunction (FNo: Integer; p1, p2, p3: Variant; var val: Variant); override; end; constructor TMyFunctionLibrary.Create; begininherited Create; with List dobeginAdd ( 'DATETOSTR '); Add (' SUMTOSTR '); End; End; Procedure TmyfunctionLibrary.dofunction (fno: integer; p1, p2, p3: variant; var val: variant); beginval: = 0; case fno OF0: val: = my_dateconvertion_routine (frParser.Calc (p1)); 1: val: = My_SumConvertion_Routine (frParser.Calc (p1)); end; end; to register the library, call frRegisterFunctionLibrary (TMyFunctionLibrary); to uninstall the library, call frUnRegisterFunctionLibrary (TMyFunctionLibrary); Q: How do I add my function to the function list (with expression generator)? A: Using the FRADDFunctionDesc process (in fr_class unit): FRADDFunctionDesc (Funclib, 'SUMTOSTR', 'My functions',' SUMTOSTR () / Converts Number To ITS Verbal Presentation. '); Note: "/" The symbol is required! 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 DobeGIN // Create a classification (name with blank) Variables ['new category']: = '; // creation Variable Variables ['new variable']: = 'CustomerData.customers. "Custno"'; variables ['another variable']: = 'Page #'; end; q: I defined string variable: with frReport1.dictionary Dovariables ['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 DOVARIABLES ['MONTH']: = '' '' 'March' '' '; or, 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 dobegin // Close this dataset DISABLEDDATASTS.ADD ('CustomerData.bio'); //, turn off the entire data module / form disabledDataSets.add ('CustomerData *' ); END; Q: How do I transfer data to the 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 created a name "My Variable", Variable value of 10 is 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; variant); beginif parname = 'myfield' TenparValue: = table1myfield.value; end; Final, the third method is to define variables in a data dictionary (you can refer to previous Problem): with frReport1.dictionary Dobeginvariables ['myvariable']: = 'CustomerData.customers. "Custno"'; variables ['Another variable']: = '10'; end; Q: I can transfer between reports and program Data? A: Use the frvariables object. If you write the following code in 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']; ---------------- Script (Fastreport Pascal) -------------------------------- Q: Can I use scripts in BAN? A: Of course. Select Band, then press Ctrl Enter or select the "OnBeforePrint" attribute 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 Refined Report Designer?

A: See TfrDesigner assembly which has several required events: OnLoadReport and OnSaveReport short code examples here: procedure TForm1.frDesigner1LoadReport (Report: TfrReport; var ReportName: String; var Opened: Boolean);.. Beginwith MyOpenDialog dobeginOpened: = ShowModal = mrOk; if Opened thenbeginReport.LoadFromBlobField (...); ReportName: = ...; end; end; end; procedure TForm1.frDesigner1SaveReport (Report: TfrReport; var ReportName: String; SaveAs: Boolean; var Saved: Boolean) ; beginif SaveAs thenwith MySaveDialog dobeginSaved: = ShowModal = mrOk; if Saved thenbeginReport.SaveToBlobField (...); ReportName: = ...; end; endelseReport.SaveToBlobField (...); end; Q: in the QR, I You can write this code: qrlabel1.caption: = 'some text'. Can I do this with 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. VART: TFRMEMOVIEW; Begint: = TfrMemoview (FRREPORT1.FINDOBJECT ('Memo1')); if t <> NIL TENT.MEMO.TEXT: = 'fastreport'; end; q: I want to preview (TFRPREVIEW components) Define hotkey?

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 Freeereport 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. Finally, return to the source code. FR_Class: Function ReadString (Stream: TStream): string; begin {if frVersion> = 23 Then} Result: = frreadstring (stream) {Elseresult: = frReadString22 (Stream);} end; procedure ReadMemo (Stream: TStream; Memo: TStrings); begin {if frVersion> = 23 then} frReadMemo (Stream, Memo) {elsefrReadMemo22 (Stream, Memo);} end; FR_Utils: procedure FRREADMEMO (Stream: TSTREAM; L: TSTRINGS); VARS: String; B: Byte; N: Word; Beginl.clear; L.Text: = frreadstring (stream); EXIT; STREAM.READ (N, 2); if n > 0 tellatstream.read (n, 2); setlength (s, n); stream.read (s [1], n); L.Add (s); stream.read (b, 1); Until B = 0ELSestReam .Read (B, 1); End; Function FRREADSTRING (Stream: TSTREAM): String; Vars: String; N: Integer; B: Byte; Beginstream.read (n, 4); setlength (s, n); stream. Read (S [1], N); if (n> 0) and (s [n] = # $ 0a) TensetLength (S, N - 2); // stream.read (b, 1); Result: = S; END; Q: How do I not print the report in the print preview? A: Here there is a code: frReport1.preparereport; FRREPORT1.PRINTPREPAREDREPORT ('', 1, true, frall); or frReport1.PrintPrePrePortdlg; 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: Use TFRREPORT.ONBEFOREPRINT Event: if View.name = 'Picture1' TentfrPictureView (View) .Picture.loadFromFile (...) or .ssign or. Anything you want to do.

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

New Post(0)