Using Custom Functions in a Report  在报表中使用自己义函数

 

FastReport has a large number of built-in standard functions for use in report designs. FastReport also allows custom functions to be written and used. Functions are added using the “FastScript” library interface, which is included in FastReport (to learn more about FastScript refer to it’s library manual).

Let's look at how procedures and/or functions can be added to FastReport. The number and types of parameters vary from function to function. Parameters of “Set” and “Record" type are not supported by FastScript, so they must be implemented using simpler types, for instance a TRect can be passed as four integers : X0, Y0, X1, Y1. There is more about the use of functions with various parameters in the FastScript documentation.

注意:自定义函数的参数不支持Set和Record类型,TRect 类型转换成4个参数传递。

In the Delphi form declare the function or procedure and its code.

在Delphi窗体中定义函数或过程:

function TForm1.MyFunc(s: String; i: Integer): Boolean;

begin

// required logic

end;

procedure TForm1.MyProc(s: String);

begin

// required logic

end;

Create the “onUser” function handler for the report component.  //编写报表组件的OnUserFunction 事件

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;

 

Use the report component’s add method to add it to the function list (usually in the “onCreate” or “onShow” event of the Delphi form).

或者调用报表组件的AddFunction方法注册函数或过程:

frxReport1.AddFunction('function MyFunc(s: String; i: Integer):Boolean');

frxReport1.AddFunction('procedure MyProc(s: String)');

 

The added function can now be used in a report script and can be referenced by objects of the “TfrxMemoView” type. The function is also displayed on the "Data tree" functions tab. On this tab functions are divided into categories and when selected a hint about the function appears in the bottom pane of the tab.

 

Modify the code sample above to register functions in separate categories, and to display descriptive hints:

把函数或过程添加到新的分类或是一组已经有分类中:

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');

The added functions will appear under the category “My functions”.

To register functions in an existing categories use one of the following category names:

- 'ctString'  string function

- 'ctDate'  date/time functions

- 'ctConv'  conversion functions

- 'ctFormat' formatting

- 'ctMath'  mathematical functions

- 'ctOther'  other functions

 

If the category name is left blank the function is placed under the functions tree root. To add a large number of functions it is recommended that all logic is placed in a separate library unit. Here is an example:

如果分类名称为空白,则该函数被放置在功能树的根。要添加大量的自定义函数,建议将所有代码放在一个单独的文件中。下面是个例子:

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

// required logic

end;

procedure MyProc(s: String);

begin

// required 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.

 

Save the file with a .pas extension then add a reference to it in the “uses” clause of your Delphi project’s form. All your custom functions will then be available for use in any report component, without the need to write code to add these functions to each “TfrxReport” and without the need to write additional code for each report component’s “onUser” function handler.

保存成文件,然后在项目中引用这个文件。所有的自定义函数就可以在任何报表组件中使用,而不需要每一个“TfrxReport”组件编写代码或事件来添加这些自定义函数。

[翻译] Using Custom Functions in a Report 在报表中使用自己义函数的更多相关文章

  1. PowerDesigner导出Report通用报表

    PowerDesigner导出Report通用报表 通用模板下载地址:http://pan.baidu.com/s/1c0NDphm

  2. Crystal Report在.net中的两种显示方式

    Crystal Report在.net中的两种显示方式 编写人:CC阿爸 2014-7-29 近来在完成深圳一公司的项目,对方对各方面要求相当严格,一不满意就拒绝签收,为了对修正水晶报表显示及导出的一 ...

  3. 检查.net代码中占用高内存函数(翻译)

    哈哈,昨天没事做,在CodeProject瞎逛,偶然看到这篇文章,居然读得懂,于是就翻译了一下,当练习英语,同时增强对文章的理解,发现再次翻译对于文章的一些细节问题又有更好的理解.下面是翻译内容,虽然 ...

  4. C# WinForm开发系列 - Crystal Report水晶报表

    转自:ttp://www.cnblogs.com/peterzb/archive/2009/07/11/1521325.html 水晶报表(Crystal Report)是业内最专业.功能最强的报表系 ...

  5. Crystal Report - 水晶报表导出文件的格式设置

    水晶报表中自带的导出和打印功能用起来确实很方便,只不过有时候需要导出的文件并不需要那么多种类型,在网上找到一些朋友的代码总结了一下,可以通过代码实现自定义导出文件类型 首先需要定义一个枚举: publ ...

  6. 【翻译】Flink Table Api & SQL —Streaming 概念 —— 表中的模式匹配 Beta版

    本文翻译自官网:Detecting Patterns in Tables Beta  https://ci.apache.org/projects/flink/flink-docs-release-1 ...

  7. Report List 报表开发

    1. Report List的输出定义 * ...NO STANDARD PAGE HEADING: 输出的报表不包含表头: * ...LINE-SIZE col : 输出的报表不包含表头: * .. ...

  8. [翻译]Writing Custom Report Components 编写自定义报表组件

    摘要:简单介绍了如何编写一个FastReport的组件,并且注册到FastReport中使用.   Writing Custom Report Components 编写自定义报表组件 FastRep ...

  9. [翻译]Writing Custom DB Engines 编写定制的DB引擎

    Writing Custom DB Engines  编写定制的DB引擎   FastReport can build reports not only with data sourced from ...

随机推荐

  1. Spring ThreadPoolTaskExecutor

    1. ThreadPoolTaskExecutor配置 1 <!-- spring thread pool executor --> 2 <bean id="taskExe ...

  2. RabbitMQ 高可用集群搭建

    面向EDA(事件驱动架构)的方式来设计你的消息 AMQP routing key的设计 RabbitMQ cluster搭建 Mirror queue policy设置 两个不错的RabbitMQ p ...

  3. CentOS7.0重置Root的密码 (忘记密码)

    首先进入开启菜单,按下e键进入编辑现有的内核,如下图所示 然后滚动列表,找到ro,将它替换成rw,并加上init=/sysroot/bin/sh,最终变为如下图 然后按CTRL+X进入到单用户模式,在 ...

  4. Python实现的常用排序方法

    1.冒泡排序,相邻位置比较大小,将比较大的(或小的)交换位置 def maopao(a):     for i in range(0,len(a)):         for j in range(0 ...

  5. linux分区之gpt(大于2T的分区)

    1.文件系统限制: ext3块尺寸 最大文件尺寸 最大文件系统尺寸1KiB  16GiB  2TiB2KiB  256GiB  8TiB4KiB  2TiB  16TiB8KiB  16TiB  32 ...

  6. form表单的默认提交行为

    一 如果<form></form>表单中只有一个<input type="text"/>,则使文本框获取焦点,并单击回车,form会自动提交. ...

  7. Mac下MySQL卸载方法

    mac下mysql的DMG格式安装内有安装文件,却没有卸载文件……很郁闷的事.1 sudo rm /usr/local/mysql2 sudo rm -rf /usr/local/mysql*3 su ...

  8. Spring框架的AOP的底层实现

    1. Srping框架的AOP技术底层也是采用的代理技术,代理的方式提供了两种 1. 基于JDK的动态代理 * 必须是面向接口的,只有实现了具体接口的类才能生成代理对象 2. 基于CGLIB动态代理 ...

  9. Spring框架的IOC核心功能快速入门

    2. 步骤一:下载Spring框架的开发包 * 官网:http://spring.io/ * 下载地址:http://repo.springsource.org/libs-release-local/ ...

  10. BZOJ 1430 小猴打架 - prufer数列

    描述 一开始森林里面有N只互不相识的小猴子,它们经常打架,但打架的双方都必须不是好朋友.每次打完架后,打架的双方以及它们的好朋友就会互相认识,成为好朋友.经过$N-1$次打架之后,整个森林的小猴都会成 ...