使用报表变量时,引用“frxVariables”单元。 变量定义在“TfrxVariable” 类:

TfrxVariable = class(TCollectionItem)

published

property Name: String;     //Name of a variable

property Value: Variant;    //Value of a variable

end;

变量列表在“TfrxVariables” 类,有所有相关的方法:

TfrxVariables = class(TCollection)

public

function Add: TfrxVariable;   //Adds a variable to the end of the list

function Insert(Index: Integer): TfrxVariable;   //Adds a variable to the given position of the list

function IndexOf(const Name: String): Integer;   //Returns the index of a variable with the given name

procedure AddVariable(const ACategory, AName: String; const AValue: Variant);  //Adds a variable to the specified category

procedure DeleteCategory(const Name: String);   //Deletes a category and all its variables

procedure DeleteVariable(const Name: String);   //Deletes a variable

procedure GetCategoriesList(List: TStrings; ClearList: Boolean = True);   //Returns the list of categories

procedure GetVariablesList(const Category: String; List: TStrings);  //Returns the list of variables in the specified category

property Items[Index: Integer]: TfrxVariable readonly;  //The list of variables

property Variables[Index: String]: Variant; default;  //Values of variables

end;

如果变量的列表很长,可以按类别分组。例如,当有下列变量列表:

Customer name

Account number

in total

total vat

可以使用以下方式:

Properties

  Customer name

  Account number

Totals

  In total

  total vat

有以下局限:

- 必须创建至少一个类别

- 类别在data tree下层, 变量在第二层

- 类别不能嵌套

- 变量的名称必须是唯一的,在整体列表中,而不是在一个类别中

 

一:创建一个变量列表

A link to the report variables is stored in the “TfrxReport.Variables” property. To create a list manually, the following steps must be performed:

- clear the list

- create a category

- create variables

- repeat the 2 and 3 steps to create another category

二:清空变量列表

It is performed with the help of the “TfrxVariables.Clear” method:

frxReport1.Variables.Clear;

三:添加分类

必需至少创建一个类别, 类别和变量保存在一个list。 类别不同于变量是以一个空格开始,这是名字的第一个符号.所有的变量都是属于这一类别。

有两个方法添加类别:

frxReport1.Variables[' ' + 'My Category 1'] := Null;

or

var

Category: TfrxVariable;

Category := frxReport1.Variables.Add;

Category.Name := ' ' + 'My category 1';

四:添加变量

添加变量必须在类别添加以后, 在列表中变量名必须唯一, 并且必须在类别中。

这里有几个方法添加变量到列表:

frxReport1.Variables['My Variable 1'] := 10; //  添加(如果不存在) 或修改一个变量的值。

var

Variable: TfrxVariable;

Variable := frxReport1.Variables.Add;

Variable.Name := 'My Variable 1';

Variable.Value := 10;

以上2个方法都把变量添加到列表最后, 因此, 添加到最后的类别. 如果想添加到列表的指定位置,使用“Insert” 方法:

var

Variable: TfrxVariable;

Variable := frxReport1.Variables.Insert(1);

Variable.Name := 'My Variable 1';

Variable.Value := 10;

添加到指定的类别,使用“AddVariable” 方法:

frxReport1.Variables.AddVariable('My Category 1', 'My Variable 2', 10);

五:删除变量

frxReport1.Variables.DeleteVariable('My Variable 2');

六:删除分类

frxReport1.Variables.DeleteCategory('My Category 1');

七:修改变量值

八:脚本变量

你可以在TfrxReport.Script中定义脚本变量,用来代替report变量, 看看 report变量和 script变量的不同:

 

Report variables

Script variables

位置

In the report variables list, TfrxReport.Variables.

In the report script, TfrxReport.Script.Variables.

Variable name

May contain any symbols.

May contain any symbols. But if you want to use that variable inside the report script, its name should conform to Pascal identificator specifications.

Variable value

May be of any type. Variables of string type are calculated each time you access them, and are, in itself, an expressions.

May be of any type. No calculation is performed, behavior is like standard language variable.

可访问性

Programmer can see the list of report variables in the "Data tree" window.

The variable is not visible, programmer should know about it.

 

Working with script variables is easy. Just assign value to the variable this way:

frxReport1.Script.Variables['My Variable'] := 'test';

In this case FastReport will create a variable if it is not exists, or assign a value to it. There is no need to use extra quotes when assigning a string to that variable.

九:TfrxReport.OnGetValue中传递变量值

最后一种传递值到报表中的方法是使用 TfrxReport.OnGetValue 事件,这个方式可以得到动态值,以前的方法通过静态值。

举例说明使用方法. 报表中放一个文本对象,输入以下内容:

[My Variable]

创建 TfrxReport.OnGetValue 事件:

procedure TForm1.frxReport1GetValue(const VarName: String; var Value: Variant);

begin

if CompareText(VarName, 'My Variable') = 0 then

Value := 'test'

end;

运行报表,我们看到变量是显示正确的。 事件TfrxReport.OnGetValue 在遇到所有未知变量时调用 。

[翻译] FastReport 变量列表使用的更多相关文章

  1. FastReport 变量列表使用

    使用报表变量时,引用“frxVariables”单元. 变量定义在“TfrxVariable” 类: TfrxVariable = class(TCollectionItem) published p ...

  2. Jenkins可用环境变量列表以及环境变量的使用(Shell/Command/Maven/Ant)

    一.可用环境变量列表(以下来自google翻译): BRANCH_NAME 对于多分支项目,这将被设置为正在构建的分支的名称,例如,如果您希望从而master不是从特征分支部署到生产. CHANGE_ ...

  3. 存储过程里面使用in变量列表异常的处理

    在写一个存储过程的时候,由于需要用到类似:select id,name from tablename where id in(id1,id2,id3...)的查询语句,同时括号里面的变量是拼接得到的, ...

  4. Phpcms所有系统变量列表 Phpcms V9 文件目录结构

    Phpcms所有系统变量列表 用户变量: view plaincopy to clipboardprint? $_userid    用户id   $_username 用户名   $_areaid  ...

  5. Shell特殊变量列表

    特殊变量列表 变量 含义 $0 当前脚本的文件名 $n 传递给脚本或函数的参数.n 是一个数字,表示第几个参数.例如,第一个参数是$1,第二个参数是$2. $# 传递给脚本或函数的参数个数. $* 传 ...

  6. shell-特殊变量列表

    特殊变量列表 变量 含义 $0 当前脚本的文件名 $n 传递给脚本或函数的参数.n $# 传递给脚本或函数的参数个数. $* 传递给脚本或函数的所有参数.有引号则引号内,作为一个参数传入. $@ 传递 ...

  7. UNIX高级环境编程(8)进程环境(Process Environment)- 进程的启动和退出、内存布局、环境变量列表

    在学习进程控制相关知识之前,我们需要了解一个单进程的运行环境. 本章我们将了解一下的内容: 程序运行时,main函数是如何被调用的: 命令行参数是如何被传入到程序中的: 一个典型的内存布局是怎样的: ...

  8. [翻译] FastReport TfrxReport组件使用

    一:加载和保存报表 报表默认保存在项目窗体文件中,大多数情况下,没有更多的操作要深圳市, 因此,你不需要采取特别措施来载入报告.如果你决定保存报表到文件或是数据库中 (这样更灵活, 比如修改报表不用重 ...

  9. Python 学习笔记5 变量-列表

    列表是python常用的一种变量. 是由一些列按照特定顺序排列的元素组成的.你可以创建包含字母表中的所有字母,数字.可以将任何东西都加入到列表中. 通常情况下,列表中都包含多个元素,所以建议变量的名称 ...

随机推荐

  1. springMVC将处理的后的数据通过post方法传给页面时,可能会出现乱码问题,下面提出解决post乱码问题的方法

    在web.xml中加入: <!-- 解决post乱码问题 --> <filter> <filter-name>CharacterEncodingFilter< ...

  2. Spring基于AspectJ的AOP的开发之AOP的相关术语

    1. Joinpoint(连接点) -- 所谓连接点是指那些被拦截到的点.在spring中,这些点指的是方法,因为spring只支持方法类型的连接点(任何一个方法都可以称为连接点) 2. Pointc ...

  3. windows常用运行命令总结

    开始→运行→命令集锦 winver---------检查Windows版本 wmimgmt.msc----打开windows管理体系结构(WMI) wupdmgr--------windows更新程序 ...

  4. canvas学习持续更新

    参考:菜鸟教程,canvas教程 绘制一个简单的矩形 <body> <canvas id="myCanvas" width="200" hei ...

  5. 面向对象设计模式纵横谈:Builder 生成器模式(笔记记录)

    Builder模式的缘起 假设创建游戏中的一个房屋House设施,该房屋的构建由几个部分组成,且各个部分要富于变化. 如果使用最直观的设计方法,每一个房屋部分的变化,都将导致房屋构建的重新修正…… 动 ...

  6. BZOJ4407 于神之怒加强版 - 莫比乌斯反演

    题解 非常裸的莫比乌斯反演. 但是反演完还需要快速计算一个积性函数(我直接用$nlogn$卷积被TLE了 推荐一个博客 我也不想再写一遍了 代码 #include<cstring> #in ...

  7. Codeforces 689C. Mike and Chocolate Thieves 二分

    C. Mike and Chocolate Thieves time limit per test:2 seconds memory limit per test:256 megabytes inpu ...

  8. Codeforces 689B. Mike and Shortcuts SPFA/搜索

    B. Mike and Shortcuts time limit per test: 3 seconds memory limit per test: 256 megabytes input: sta ...

  9. 官网类原型模板分享——Apple

    苹果公司是美国一家高科技公司,引领全球数码产品设计潮流,是世界最具价值的品牌. 此原型正是取自苹果公司官网,网站主要以展示产品为主,排版方式采用大图配简练的文字,清爽简洁的同时突出产品优势,增大产品的 ...

  10. easyui-从数据库读取创建无极菜单

    easyui-tree基础必须知道这个如下: 树控件使用<ul>元素定义.标签能够定义分支和子节点.节点都定义在<ul>列表内的<li>元素中.以下显示的元素将被用 ...