Fast report 4 用代码创建一个报表_第1页
Fast report 4 用代码创建一个报表_第2页
Fast report 4 用代码创建一个报表_第3页
Fast report 4 用代码创建一个报表_第4页
Fast report 4 用代码创建一个报表_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Creating a report form from code用代码创建报表As a rule, you will create most reports using the designer. Nevertheless, in some cases (for example, when the reports form is unknown) it is necessary to create a report manually, from code.作为一个原则,你应该使用设计器(Designer) 创建绝大部分报表.尽管如此,在一些案例(比如,当报表的表单还是未知的情况下).手动使用代

2、码来创建报表就有必要了.To create a report manually, one should perform the following steps in order:- clear the report component- add data sources- add the Data page- add reports page- add bands on a page- set bands properties, and then connect them to the data- add objects on each band- set objects properties

3、, and then connect them to the data要手动创建一个报表,我们应该安装如下步骤:- 清除报表控件- 加入数据源- 加入数据页(“Data” page)- 加入报表页- 加入报表段- 设置报表段的属性,然后将它连接到数据- 在每个报表段上加入对象- 设置对象的属性,然后将它们连接到数据Let us examine creation of a simple report of the list type. Assume that we have the following components: frxReport1: TfrxReport and frxDBDat

4、aSet1: TfrxDBDataSet (the last one is connected to data from the DBDEMOS, the Customer.db table). Our report will contain one page with the Report Title and Master Data bands. On the Report Title band there will be an object with the Hello FastReport! text, and the Master Data one will contain an ob

5、ject with a link to the CustNo field.Pascal:varDataPage:TfrxDataPage;Page:TfrxReportPage;Band:TfrxBand;DataBand:TfrxMasterData;Memo:TfrxMemoView;clearareportfrxReport1.Clear;addadatasettothelistofonesaccessibleforareportfrxReport1.DataSets.Add(frxDBDataSet1);addtheDatapageDataPage:=TfrxDataPage.Crea

6、te(frxReport1);addapagePage:=TfrxReportPage.Create(frxReport1);createauniquenamePage.CreateUniqueName;setsizesoffields,paperandorientationbydefaultPage.SetDefaults;modifypapersorientationPage.Orientation:=poLandscape;addareporttitlebandBand:=TfrxReportTitle.Create(Page);Band.CreateUniqueName;itissuf

7、ficienttosettheTopcoordinateandheightforabandbothcoordinatesareinpixelsBand.Top:=0;Band.Height:=20;addanobjecttothereporttitlebandMemo:=TfrxMemoView.Create(Band);Memo.CreateUniqueName;Memo.Text:=HelloFastReport!;Memo.Height:=20;thisobjectwillbestretchedaccordingtobandswidthMemo.Align:=baWidth;addthe

8、masterdatabandDataBand:=TfrxMasterData.Create(Page);DataBand.CreateUniqueName;DataBand.DataSet:=frxDBDataSet1;theTopcoordinateshouldbegreaterthanthepreviouslyaddedbandstop+heightDataBand.Top:=100;DataBand.Height:=20;addanobjectonmasterdataMemo:=TfrxMemoView.Create(DataBand);Memo.CreateUniqueName;con

9、necttodataMemo.DataSet:=frxDBDataSet1;Memo.DataField:=CustNo;Memo.SetBounds(0,0,100,20);adjustthetexttotherightobjectsmarginMemo.HAlign:=haRight;showthereportfrxReport1.ShowReport;C+:TfrxDataPage*DataPage;TfrxReportPage*Page;TfrxBand*Band;TfrxMasterData*DataBand;TfrxMemoView*Memo;/clearareportfrxRep

10、ort1-Clear();/addadatasettothelistofonesaccessibleforareportfrxReport1-DataSets-Add(frxDBDataset1);/addtheDatapageDataPage=newTfrxDataPage(frxReport1);/addapagePage=newTfrxReportPage(frxReport1);/createauniquenamePage-CreateUniqueName();/setsizesoffields,paperandorientationbydefaultPage-SetDefaults(

11、);/modifypapersorientationPage-Orientation=poLandscape;/addareporttitlebandBand=newTfrxReportTitle(Page);Band-CreateUniqueName();/itissufficienttosettheTopcoordinateandheightforaband/bothcoordinatesareinpixelsBand-Top=0;Band-Height=20;/addanobjecttothereporttitlebandMemo=newTfrxMemoView(Band);Memo-C

12、reateUniqueName();Memo-Text=HelloFastReport!;Memo-Height=20;/thisobjectwillbestretchedaccordingtobandswidthMemo-Align=baWidth;/addthemasterdatabandDataBand=newTfrxMasterData(Page);DataBand-CreateUniqueName();DataBand-DataSet=frxDBDataset1;/theTopcoordinateshouldbegreaterthanthepreviouslyaddedbandsto

13、p+heightDataBand-Top=100;DataBand-Height=20;/addanobjectonmasterdataMemo=newTfrxMemoView(DataBand);Memo-CreateUniqueName();/connecttodataMemo-DataSet=frxDBDataset1;Memo-DataField=CustNo;Memo-SetBounds(0,0,100,20);/adjustthetexttotherightobjectsmarginMemo-HAlign=haRight;/showthereportfrxReport1-ShowR

14、eport(true);Let us explain some details.All the data sources, which are to be used in the report, must be added to the list of data sources. In our case, this is performed using the frxReport1.DataSets.Add(frxDBDataSet1) line. Otherwise, a report will not work. The Data page is necessary for inserti

15、ng internal datasets such as TfrxADOTable into the report. Such datasets can be placed only to the Data page.The call for Page.SetDefaults is not necessary, since in this case a page will have the 4 format and margins of 0 mm. SetDefaults sets 10mm margins and takes page size and alignment, which a

16、printers have by default.While adding bands to a page, you should make sure they do not overlap each other. To perform this, it is sufficient to set the Top and Height coordinates. There is no point in modifying the Left and Width coordinates, since a band always has the width of the page, on which

17、it is located (in case of vertical bands its not true you should set Left and Width properties and dont care about Top and Height). One should note, that the order of bands location on a page is of great importance. Always locate bands in the same way you would do it in the designer.Objects coordinates and sizes are set in pixels. Since the Left, Top, Width, and Height properties of all objects have the Extended type, you can point out non-in

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论