fastreport 示例

[FORMATDATETIME(‘mm-dd‘, [IBqryShipDate."CLOSEDATE"])] [FORMATDATETIME(‘mm/dd/yy‘, [IbqryOrderForm."ORDERDATE"])] 金額總計:[FORMATFLOAT(‘#########0.00‘, [TotalAmount])] 訂單數量:[COUNT(band1)] 數量合計:[SUM([IBqryShipDate."QUANTITY"])] 婚否:[IF([IbqryPersonal."ISMARRIAGED"]=1, ‘是‘, ‘否‘)] [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."工序名稱"])) mod 35 =0 then begin bMData.height := 20 * INT(Length(Trim([MainADOQuery."工序名稱"]))/35); Memo39.Height := 20 * INT(LENGTH(TRIM([MainADOQuery."工序名稱"]))/35); end else begin bMData.height := 20 * (INT(Length(Trim([MainADOQuery."工序名稱"]))/35)+1); Memo39.Height := 20 * (INT(LENGTH(TRIM([MainADOQuery."工序名稱"]))/35)+1); end Fast Report 問題集 [email protected] ---------------- 使用自定義函數 ---------------------------------------- Q: 我怎樣添加我的自定義函數? A: 使用 TfrReport.OnUserFunction 事件. 這裏有一個簡單的例子: 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; 然後,你就可以在報表(任何表達式或腳本)的任何地方使用 SumToStr 函數了。 Q: 但是它僅僅能工作在一個TfrReport組件中。可我想在任何地方(在所有的TfrReport組件中)使用的我的自定義函數? A: 使 OnUserFunction event 句柄作爲所有組件的公用句柄。如果你不能做到這一點,你需要創建函數庫: 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 of 0: val := My_DateConvertion_Routine(frParser.Calc(p1)); 1: val := My_SumConvertion_Routine(frParser.Calc(p1)); end; end; 要註冊函數庫,調用 frRegisterFunctionLibrary(TMyFunctionLibrary); 要卸載函數庫,調用 frUnRegisterFunctionLibrary(TMyFunctionLibrary); Q: 我怎樣將我的函數添加到函數列表中 (用表達式生成器)? A: 使用 frAddFunctionDesc 過程 (在FR_Class 單元中): frAddFunctionDesc(FuncLib, ‘SUMTOSTR‘, ‘My functions‘, ‘SUMTOSTR(<Number>)/Converts number to its verbal presentation.‘); 注意: "/" 符號是必須的! 它從它的描述中分隔函數語法。 FuncLib 被聲明爲你自己的函數庫 (如果你不使用函數庫可以將其設置爲nil). 當函數庫未註冊時,所有它的函數將自動從函數列表中刪除。 ---------------- 使用變量 ------------------------------------- Q: 我怎樣編程實現填充變量列表(在數據詞典中)? A: 數據詞典中的所有變量及分類都被存儲在 TfrReport.Dictionary.Variables 中. with frReport1.Dictionary do begin // 創建分類(名稱用空白) Variables[‘ New category‘] := ‘‘; // 創建變量 Variables[‘New Variable‘] := ‘CustomerData.Customers."CustNo"‘; Variables[‘Another Variable‘] := ‘Page#‘; end; Q: 我定義了字符串變量: with frReport1.Dictionary do Variables[‘Month‘] := ‘March‘; 但是當我運行報表是,出現了錯誤,爲什麼? A: 因爲 FastReport 假定數據詞典中的字符串變量值是一個表達式,它需要分析、計算它。 可以使用其它的方法: with frReport1.Dictionary do Variables[‘Month‘] := ‘‘‘‘ + ‘March‘ + ‘‘‘‘; 或者, 使用 frVariables 來傳輸固定數據到報表。 Q: 我不想在數據詞典中顯示某些數據集? A: 使用 TfrReport.Dictionary.DisabledDatasets: with frReport1.Dictionary do begin // 關閉該數據集 DisabledDatasets.Add(‘CustomerData.Bio‘); // 或者, 關閉整個數據模塊/窗體 DisabledDatasets.Add(‘CustomerData*‘); end; Q: 我怎樣將數據傳送到報表? A: 有幾個方法可以實現它. 第一是使用全局對象 frVariables (在 FR_Class 單元中被定義): frVariables[‘My variable‘] := 10; 這段代碼創建了一個名稱爲“My variable”,值爲 10 的變量。這是最好的傳輸固定數據的報表的方法。 第二種方法是使用 TfrReport.OnGetValue 事件. 這可以使用這個方法來傳送動態數據、記錄等。 procedure TForm1.frReport1GetValue(ParName: String; var ParValue: Variant); begin if ParName = ‘MyField‘ then ParValue := Table1MyField.Value; end; 最後, 第三種方法是通過編程在數據詞典中定義變量(可以參考以前的問題): with frReport1.Dictionary do begin Variables[‘MyVariable‘] := ‘CustomerData.Customers."CustNo"‘; Variables[‘Another Variable‘] := ‘10‘; end; Q: 我能在報表和程序間傳送數據嗎? A: 使用 frVariables 對象. 如果你在報表的任何對象的腳本中寫入以下代碼: MyVariable := 10 那麼,在你的程序中,你可以使用以下代碼來獲取 MyVariable 的值: v := frVariables[‘MyVariable‘]; ---------------- 腳本 (FastReport Pascal) --------------------------------- Q: Band 中是否可以使用腳本? A: 當然. 選擇 band ,然後按 Ctrl+Enter 或在對象瀏覽器中選擇 "OnBeforePrint" 屬性。 Q: 報表頁中是否可以使用腳本? A: 當然. 選擇頁 (在空白處單擊) ,然後在對象瀏覽器中選擇 "OnBeforePrint" 屬性。如果該頁是一個對話框窗體,那麼這個屬性就是 "OnActivate". Q: 我有兩個對象: Memo1 和 Memo2. 我能否在 Memo1 的腳本中調用 Memo2 的屬性和方法? A: 當然, 例如,你可以這樣做: 對象名.屬性名. Q: 在腳本中,我可以使用對象的哪些屬性? A: 幾乎所有你能在對象瀏覽器中看到的屬性。例如,可以使用 Font.Name, Font.Size等來存取字體屬性。 ---------------- 其它問題 -------------------------------------------- Q: 怎樣改變多頁報表中某一頁的順序? A: 拖動頁標籤到目的位置。 Q: 我想查看所有的字段及變量,我想在報表中使用列表來實現它? A: 設置 TfrReport.MixVariablesAndDBFields := True.現在,所有的數據字段及變量可在“插入數據字段”對話框中可存取了。 Q: 我不想顯示導入選項對話框? A: 在導入組件(比如,TfrTextExport)中設置所有必需的選項,然後通過設置ShowDialog屬性爲False來關閉此對話框。 Q: 爲什麼 TotalPages 變量不起作用? 它總是返回 0. A: 在你的報表中設置 Two-pass 選項. 要設置它,你需要在報表設計器的“文件”菜單中,打開“報表選項”對話框。 Q: 我用BLOB字段來存儲我的報表。當我運行報表設計器時,它顯示我的報表未命名? A: 在運行報表設計器前,這樣做: frReport1.FileName := ‘Name of my report‘; Q: 我想在重新定義報表設計器中的“打開”及“保存”按鈕的功能? A: 查看 TfrDesigner 組件. 它有幾個必需的事件: OnLoadReport 和 OnSaveReport. 這裏有一小段代碼例子: 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: 在 QR 中, 我可以寫這樣的代碼: QRLabel1.Caption := ‘Some text‘. 我可以用FR這樣做嗎? A: FR 對象並不是一個組件 (這並不像 QR, RB). 但使用 TfrReport.FindObject 方法可以通過對象名稱找到該對象。 var t: TfrMemoView; begin t := TfrMemoView(frReport1.FindObject(‘Memo1‘)); if t <> nil then t.Memo.Text := ‘FastReport‘; end; Q: 我想在用戶預覽(TfrPreview組件)中自定義熱鍵? A: 這個組件有個窗口: Tform 屬性. 將自定義句柄指定到 Window.OnKeyDown 屬性. Q: Fast Report 2.4 不能裝載 FreeReport 2.21 文件? A: 這僅需要使用16進制數改變報表文件的第一字節,然後在源代碼中修改下面的部分。在這些修改之後, 裝載報表並保存它. 最後,返回到源代碼處. 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: 怎樣不在打印預覽中打印報表? A: 這裏有一段代碼: frReport1.PrepareReport; frReport1.PrintPreparedReport(‘‘, 1, True, frAll); 或 frReport1.PrintPreparedReportDlg; Q: 我想在報表中旋轉圖片。問題是這張圖片是由我的應用程序生成的。是否有方法可以在打印前將這幅圖片裝載到報表中? A: 使用 TfrReport.OnBeforePrint 事件: if View.Name = ‘Picture1‘ then TfrPictureView(View).Picture.LoadFromFile(…) 或 .Assign 或 .你所想要做的任何事情

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章