一、使用TfrxReport 组件工作
1、加载并存储报表
默认情况下,报表窗体同项目窗体构存储在同一个DFM文件中。多数情况下,无须再操作,因而你就不必采用特殊方法加载报表。如果你决定在文件中存储报表窗体或者是数据库的
Blob字段(他提供了非常大的弹性,你能够在非编译程序中修改),你必须使用“TfrxReport”提供的加载和存储方法。
function LoadFromFile(const FileName: String; ExceptionIfNotFound: Boolean = False): Boolean;
从一个给定名字文件中加载报表。如果第二个参数等于“True”并且文件没找到,那么他会触发一个异常。如果文件加载成功,他返回“True”。
procedure LoadFromStream(Stream: TStream);
从流中加载报表。
procedure SaveToFile(const FileName: String);
用特殊名称文件存储报表。
procedure SaveToStream(Stream: TStream);
把报表存在流中。
例如:
Pascal:
frxReport1.LoadFromFile('c:/1.fr3');
frxReport1.SaveToFile('c:/2.fr3');
C++:
frxReport1->LoadFromFile("c://1.fr3");
frxReport1->SaveToFile("c://2.fr3");
2.设计报表
通过“TfrxReport.DesignReport”方法调用报表设计器。你必须在你的项目中包含报表设计器(必要条件是:要么使用“TfrxDesigner”组件,要么增加“frxDesgn”单元到uses
列表)
“DesigReport”方法接受两个默认参数:
procedure DesignReport(Modal: Boolean = True; MDIChild: Boolean = False);
Modal参数决定设计器是否被模态,MDIChild参数允许把设计器窗体作为一个MDI子窗体。
例如:
frxReport1.DesignReport;
3.运行报表
应用下面两个“TfrxReport”方法中的一个启动报表:
procedure ShowReport(ClearLastReport: Boolean = True);
启动报表并在预览窗体中显示。如果“ClearLastReport”参数等于“False”,报表将会增加先前的一个报表结果,否则清除前一个报表结构。
function PrepareReport(ClearLastReport: Boolean = True): Boolean;
启动报表,没有打开预览窗体,参数赋值与“ShowReport”方法同名。如果报表构造成功,他返回“True”。
多数情况下,使用第一种方法更为方便一些。在报表被构造的同时,他会立刻显示一个预览窗体。
当需要增加另一个报表到前一个报表中的时候,“ClearLastReport”参数显得方便些。(此类技术用于批量报表打印)。
例如:
frxReport1.ShowReport;
4.预览报表
使用两种途径显示一个报表是可能的:两者都是调用“TfrxReport.ShowReport”方法(先前描述过了),或者使用“TfrxReport.ShowPreparedReport”方法来帮助实现。在第二
种情况下,报表构造没有被执行,但显示了一个完成的报表。也就是说,你要么在“PreparedReport”方法帮助下构造他,要么在构造前从文件中加载报表(查看“加载/存储完
成的报表”)
例如:
Pascal:
if frxReport1.PrepareReport then
frxReport1.ShowPreparedReport;
C++:
if(frxReport1->PrepareReport(true))
frxReport1->ShowPreparedReport();
在这种情况下,报表构造器先被完成了,并显示在预览窗体中。构造一个庞大的报表可能要花费很多时间,那就是为什么使用“ShowReport”非等时同步方法会好于
“PrepareReport/ShowPreparedReport”方法。你可以通过“TfrxReport.PreviewOptions”属的缺省值设定预览参数值。(这句翻译的不够好,请参考原文)
原文参考:In this case, report construction is finished first, and after that it is displayed in the preview window. Construction of a large report can take
a lot of time, and that is why it is better to use the “ShowReport anisochronous” method, than the “PrepareReport/ShowPreparedReport” one. One can assign
preview settings by default via the “TfrxReport.PreviewOptions” property.[SPAN]5、打印报表
大多数情况下,你可以从预览窗体打印报表。要人工打印报表,你应该使用“TfrxReport.Print”方法,例如:
frxReport1.LoadFromFile(...);
frxReport1.PrepareReport;
frxReport1.Print;
同时,你可以在显示的打印对话框中设置打印参数,你也可以使用默认设定值。取消打印对话框,请参考“TfrxReport.PrintOptions”属性帮助