Introduction to Rave Reports

转载 2004年07月05日 02:45:00

Introduction to Rave Reports - Part IV: More Data Aware Reports

In Part III we have explored the data aware capabilities of Rave Reports, using the Driver Data View. On Part IV we are going to learn how to use Direct Data Views, the creation of Master/Detail reports, and the use of CalcOP and CalcTotal components to display calculated values and totals.

The Direct Data View

The Direct Data View allows you share the database connection established by your application, fetching data directly from the DataSets in your application. You can link them to any TDataSet descendant, and, with some code, you can even fetch data from custom DataStructures, like arrays of records or TStringLists. Apart from that, it behaves in the way as the Driver Data View we explored on Part III.

Using DataSet Connections

Let's create a master detail report using Direct Data Views. Create a new application, and set up a connection with your database using your favorite Db Framework. I'll still be using BDE, for demonstration purposes. Add two tables (or queries, as you prefer), selecting data from the orders and items tables. For each DataSet, add a corresponding TRvDataSetConnection, available in the Rave tab, in the pallete. Set the property DataSet of each DataSetConnection to the corresponding component, and give them meaningful names (I called them dscItems and dscOrders).

The name is important: it is the your application link to the report. You won't be able to have two DataSet connections, even in different reports, with the same name, or you might run into trouble if someone tries to run both reports concurrently.

After the DataSets are set up, return to the Rave Reports designer. Choose New Data Connection, and you should see the DataSet Connections you added to your form in the Delphi designer:


Select dscItems to create the first DataView, then repeat the process to create the DataView for dscOrders. You should now see the fields in the Project Treeview, under the newly created DataViews:


Don't forget to rename the DataViews to better names than DataView1 and DataView2.

Creating the Bands

After the DataViews have been created, we should set up the bands. Create a Region consisting of the whole page area, and add one band (Header), two DataBands (Master and Detail), and another Band (Footer). Set the ControllerBand property of Header, Detail and Footer to Master. Using the BandStyle property editor, set the style of the Header band to Body Header (B), the style of the Detail band to Detail (D), and the Footer band to Body Footer (b). Notice how the Band Display gives a nice preview of how the bands are going to printed:


You also need to link the DataView property of the Master band to dvOrders, and the Detail band to dvItems. To create the Master/Detail relashionship, set the MasterDataView property of the Detail band to dvOrders, and both the MasterKey and DetailKey properties to the field OrderNo.

The FontMaster Component

You proably want similar items (all the items in the Detail Band, for example), to print with the same font. Instead of setting each Font property individually, you can you a FontMaster. Add a FontMaster component to the page and set its Font propert to Times New Roman, 10. In the next step, when adding the Text and DataText components, set their FontMirror property to the FontMaster. Now, if you ever change your mind about the font that is going to be used in this report, you don't need to change it in every component, just change it in the FontMaster and it will be reflect in every other component that is linked to it. You can have as much FontMasters in one report as you need.

The FontMaster is a Non-Visual component, meaning it won't show in the Design Area. If you need to reselect it, you will have to do it through the Project TreeView.

Adding the DataTexts

Now its just a matter of adding Text and DataText components to the bands. Don't forget you can drag-and-drop (while pressing the ctrl and alt keys) from the Project Treeview to create them. I added OrderNo, SaleDate, Terms, PaymentMethod, AmountPaid and Freight to the Master band, and ItemNo, PartNo, Qty and Discount to the Detail band. Don't forget that the DisplayFormat of float fields is set in the fields themselves, in the Project Treeview, and not in the DataText components.

Adding Totals and Calculated Fields

You can make calculations and aggregated values using the CalcOP and CalcTotal components, available on the Report tab. The result of these calculations can be outputted to parameters, PI Vars, or used as intermediate result for other calculations. We are going to output them to parameters, so select your report in the Project Treeview and add two parameters, called AmountPaidTotal and FreightTotal:


Now add two CalcTotal components to your the Footer band, and set their Controller property to the Master band, their DataView property to dvOrders, the DataField to AmountPaid and Freight, and the DestParam to the params you created earlier, AmountPaidTotal and FreightTotal. It's also in the CalcTotal component where you define the DisplayFormat of the value printed.

Note that the Calc components are evaluated in the order they appear in the Project Treeview. If a CalcOp result is going to printed by a DataText component, make sure it appears in the Treeview before it. You can use the buttons Move Forward and Move Behind from the Alignment Toolbar to change their order.

You can now add in the Footer Band two DataText components to print those variables. Notice that is has summed the values, and you can define through the CalcType property of the the CalcTotal components the operation you would like to perform.

The sample data included in the DbDemos does not have a value for Freight in any of the records. Feel free to edit a few records to see them added up.

Now let's suppose we need to sum both totals, and display them in the footer band. Add a new parameter called Total to the report and a CalcOp component below the CalcTotal components, in the Footer band, and set the Src1DataField to Param.AmountPaidTotal, and Scr2DataField to Param.FreightTotal. Set the DestParam property to Total, and the DisplayFormat of the value. Add a DataText to print this value.

Finishing Up

To add the report to your project, just do the same as was done in the previous reports: just link it in a RvProject and call the execute method. You might want to filter the DataSet based on user input, but that's the same way as you always done before.


We have seen how to create DataAware reports using Direct Data Views, how to set up master/detail relationships, and how to use Calc components. You can find a project containing the report developed here on CodeCentral. Part V will demonstrate the use of Custom Connections and some other tricks.

Rave Reports初步入门

你可以在VCL或CLX应用程序中使用Rave Reports去实现来自数据库或非数据库数据的报表.下面的过程说明怎样增加一个简单的报表到已存在的数据库应用程序中.   1.在Delphi中打开一个数据...
  • china9797
  • china9797
  • 2005年06月08日 22:26
  • 1400

rave report的使用感想

  • depend
  • depend
  • 2005年09月05日 04:51
  • 1970


        近段时间用Delphi7的RaveReport控件做票据打程序, 遇到不少问题. 幸好在网上得到得一些前辈(有意或无意)的帮助.得到不少心得. 在此表示感谢! 同时也将自己的所得拿出来...
  • Raoxk
  • Raoxk
  • 2007年05月16日 22:35
  • 2178


一、Rave介绍 RAVE (Report Authoring Visual Environment) 是一个可视化的报表设计器。它本身是一个第三方报表软件,目前的版本是Rave5.0,由于其简单...
  • luolunz
  • luolunz
  • 2012年03月23日 13:23
  • 2628


  Rave中连接ADO数据库的例子 (1)  放置控件ADOConnection1,设定其属性    ConnectionString =      Provider=Microsoft.Jet.O...
  • yuanqingfei
  • yuanqingfei
  • 2004年07月05日 02:42
  • 1673

Delphi 7 中使用RAVE报表(一)

Delphi 7 中使用RAVE报表(一)最近刚刚做完一个项目,使用到了RAVE进行报表设计,在使用中也查阅了很多资料,但总觉得网上的资料过于分散,而且都不是很全面,所以决定将如何在Delphi 7中...
  • highway_programmer
  • highway_programmer
  • 2004年11月30日 16:16
  • 7295

Delphi 7 中使用RAVE报表(七)

Delphi 7 中使用RAVE报表(七)----  一些技巧作为《Delphi 7 中使用RAVE报表》的最后,整理一些技巧给大家。1.设计好的Rave报表文件如何打包到EXE文件中?       ...
  • highway_programmer
  • highway_programmer
  • 2005年03月21日 12:08
  • 3403

Rave报表介绍之二: 可视报表设计器

可视报表设计器 Rave有自己的可视报表设计器,以自己的文件格式保存报表。这有一些优势,你可以把报表独立于应用程序之外,可独立进行升级,甚至可以通过网络进行更新,或者使用Nevrona的Rave Re...
  • china9797
  • china9797
  • 2005年06月08日 22:38
  • 1292


TRvCustomConnection组件   描述:   通过数据连接组件的事件,你可以定制数据以何种方式送到你的Rave报表.对于使用TRvCustomConnection的非数据库数据,你会想要...
  • china9797
  • china9797
  • 2005年06月08日 22:32
  • 623


一、Rave组件:引擎类组件 引擎类组件与TrvProject组件相互配合使用,在其中不仅可以设置相应的打印参数,而且可以设置最终报表的打印机配置、纸张大小及系统的设置。 1. TRvSyst...
  • luolunz
  • luolunz
  • 2012年03月23日 13:46
  • 2717
您举报文章:Introduction to Rave Reports