翻譯|使用教程|編輯:楊鵬連|2021-07-26 09:55:10.330|閱讀 314 次
概述:FastReport 內(nèi)置了大量的標準函數(shù),用于報表設(shè)計。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
FastReport VCL是用于 Delphi、C++ Builder、RAD Studio 和 Lazarus 的報告和文檔創(chuàng)建 VCL 庫。它提供了可視化模板設(shè)計器,可以訪問 30 多種格式,并可以部署到云、網(wǎng)站、電子郵件和打印中。
FastReport 內(nèi)置了大量的標準函數(shù),用于報表設(shè)計。還可以添加您自己的自定義功能。函數(shù)連接是使用FastReport中包含的“FastScript”腳本庫接口進行的(要了解FastScript的更多信息,請參閱它的庫手冊)。
如何連接過程和/或函數(shù)的示例。函數(shù)的參數(shù)數(shù)量和類型可能會有所不同。不能傳遞“Set”和“Record”類型的參數(shù),因為FastScript不支持它們。您必須傳遞更簡單的類型的參數(shù),例如傳遞TRect為X0, Y0, X1, Y1: Integer。查看更多關(guān)于在 FastScript 文檔中添加具有不同參數(shù)的函數(shù)的過程。
在 Delphi 表單上聲明函數(shù)或過程及其代碼。
function TForm1.MyFunc(s: String; i: Integer): Boolean; begin // necessary logic end; procedure TForm1.MyProc(s: String); begin // necessary logic end;為報告組件創(chuàng)建 onuser 函數(shù)處理程序。
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 方法添加到函數(shù)列表中(通常在 Delphi 表單的 on create 或 on show 事件中)。
frxReport1.AddFunction('function MyFunc(s: String; i: Integer): Boolean'); frxReport1.AddFunction('procedure MyProc(s: String)');現(xiàn)在可以在報告腳本中使用連接函數(shù);此外,可以從TfrxMemoView類型對象中引用它。此功能也顯示在“數(shù)據(jù)樹”窗口的功能頁選項卡中。在這個窗口中,函數(shù)被分成幾類,當您選擇任何函數(shù)時,窗口底部窗格中會出現(xiàn)有關(guān)該函數(shù)的提示。
修改上面的代碼示例,將函數(shù)注冊到單獨的類別中,并顯示函數(shù)描述提示:
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');您添加的項目現(xiàn)在將顯示在“我的功能”類別下。
如果要在現(xiàn)有類別之一中注冊函數(shù),請使用以下類別名稱之一:
'ctString'——字符串函數(shù);
'ctDate' - 日期/時間函數(shù);
'ctConv' - 轉(zhuǎn)換函數(shù);
'ctFormat' - 格式化;
'ctMath' - 數(shù)學(xué)函數(shù);
'ctOther' - 其他功能。
如果指定了空白類別名稱,則函數(shù)將放置在函數(shù)樹根中。
如果您希望添加大量函數(shù),建議將所有邏輯放在一個單獨的庫單元中。下面是一個例子:
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 子句中添加對它的引用,您的所有自定義函數(shù)將可用于任何報表組件。無需編寫代碼將這些函數(shù)添加到每個TfrxReport,也無需為每個報表組件的“onuserfunction”處理程序編寫額外的代碼。
如果您對 FastReport 感興趣,歡迎加入 FastReport QQ 交流群:702295239
還想要更多嗎?您可以點擊閱讀【FastReport報表2021最新資源盤點】,查找需要的教程資源。上是FastReport .NET慧正在網(wǎng)火熱銷售中!>>查看價格詳情
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: