翻譯|使用教程|編輯:楊鵬連|2021-07-26 09:55:10.330|閱讀 331 次
概述:FastReport 內置了大量的標準函數,用于報表設計。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
FastReport VCL是用于 Delphi、C++ Builder、RAD Studio 和 Lazarus 的報告和文檔創建 VCL 庫。它提供了可視化模板設計器,可以訪問 30 多種格式,并可以部署到云、網站、電子郵件和打印中。
FastReport 內置了大量的標準函數,用于報表設計。還可以添加您自己的自定義功能。函數連接是使用FastReport中包含的“FastScript”腳本庫接口進行的(要了解FastScript的更多信息,請參閱它的庫手冊)。
如何連接過程和/或函數的示例。函數的參數數量和類型可能會有所不同。不能傳遞“Set”和“Record”類型的參數,因為FastScript不支持它們。您必須傳遞更簡單的類型的參數,例如傳遞TRect為X0, Y0, X1, Y1: Integer。查看更多關于在 FastScript 文檔中添加具有不同參數的函數的過程。
在 Delphi 表單上聲明函數或過程及其代碼。
function TForm1.MyFunc(s: String; i: Integer): Boolean; begin // necessary logic end; procedure TForm1.MyProc(s: String); begin // necessary logic end;為報告組件創建 onuser 函數處理程序。
function TForm1.frxReport1UserFunction(const MethodName: String; var Params: Variant): Variant; begin if MethodName = 'MYFUNC' then Result := MyFunc(Params[0], Params[1]) else if MethodName = 'MYPROC' then MyProc(Params[0]); end;使用報表組件的 add 方法添加到函數列表中(通常在 Delphi 表單的 on create 或 on show 事件中)。
frxReport1.AddFunction('function MyFunc(s: String; i: Integer): Boolean'); frxReport1.AddFunction('procedure MyProc(s: String)');現在可以在報告腳本中使用連接函數;此外,可以從TfrxMemoView類型對象中引用它。此功能也顯示在“數據樹”窗口的功能頁選項卡中。在這個窗口中,函數被分成幾類,當您選擇任何函數時,窗口底部窗格中會出現有關該函數的提示。
修改上面的代碼示例,將函數注冊到單獨的類別中,并顯示函數描述提示:
frxReport1.AddFunction('function MyFunc(s: String; i: Integer): Boolean', 'My functions', ' MyFunc function always returns True'); frxReport1.AddFunction('procedure MyProc(s: String)', 'My functions', ' MyProc procedure does not do anything');您添加的項目現在將顯示在“我的功能”類別下。
如果要在現有類別之一中注冊函數,請使用以下類別名稱之一:
'ctString'——字符串函數;
'ctDate' - 日期/時間函數;
'ctConv' - 轉換函數;
'ctFormat' - 格式化;
'ctMath' - 數學函數;
'ctOther' - 其他功能。
如果指定了空白類別名稱,則函數將放置在函數樹根中。
如果您希望添加大量函數,建議將所有邏輯放在一個單獨的庫單元中。下面是一個例子:
unit myfunctions; interface implementation uses SysUtils, Classes, fs_iinterpreter; // you can also add a reference to any other external library here type TFunctions = class(TfsRTTIModule) private function CallMethod(Instance: TObject; ClassType: TClass; const MethodName: String; var Params: Variant): Variant; public constructor Create(AScript: TfsScript); override; end; function MyFunc(s: String; i: Integer): Boolean; begin // necessary logic end; procedure MyProc(s: String); begin // necessary logic end; { TFunctions } constructor TFunctions.Create; begin inherited Create(AScript); with AScript do AddMethod('function MyFunc(s: String; i: Integer): Boolean', CallMethod, 'My functions', ' MyFunc function always returns True'); AddMethod('procedure MyProc(s: String)', CallMethod, 'My functions', ' MyProc procedure does not do anything''); end; end; function TFunctions.CallMethod(Instance: TObject; ClassType: TClass; const MethodName: String; var Params: Variant): Variant; begin if MethodName = 'MYFUNC' then Result := MyFunc(Params[0], Params[1]) else if MethodName = 'MYPROC' then MyProc(Params[0]); end; initialization fsRTTIModules.Add(TFunctions); end.使用 .pas 擴展名保存文件,然后在 Delphi 項目表單的 uses 子句中添加對它的引用,您的所有自定義函數將可用于任何報表組件。無需編寫代碼將這些函數添加到每個TfrxReport,也無需為每個報表組件的“onuserfunction”處理程序編寫額外的代碼。
如果您對 FastReport 感興趣,歡迎加入 FastReport QQ 交流群:702295239
還想要更多嗎?您可以點擊閱讀【FastReport報表2021最新資源盤點】,查找需要的教程資源。上是FastReport .NET慧正在網火熱銷售中!>>查看價格詳情
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自: