By: Leonel Togniolli
Abstract: This is a introduction to Rave Reports. Part III describes how to create Data Aware Reports using Driver Data Views - by Leonel Togniolli
In the previous articles, I have shown how do the Code Based engine and the
Visual Designer work. In this document, I'm going to explore the Data-Aware
capabilities of Rave Reports.
There are two ways to access data from inside a report: you
can share the same connection established by your application, fetching records
from Datasets that exists in your Forms or Datamodules, or you can configure
a new connection on the report, allowing it to be independent of a particular
application. For the first method you would use a Direct Data View,
and a Driver Data View for the second. Data View is the analog
of a DataSource/DataSet combination inside the report.
If you intend to deploy your application using
Nevrona's Rave Report Server,
you should use Driver Data Views.
Let's create a simple database report using a Driver Data View.
Start the Rave Visual Designer, and start a new project. We need to define the
database connection. To do this, choose File/New Database Object, or press the
sixth button in the toolbar (the purple cube). The Data Connections
window will appear:
Choose Database Connection, and you will be
asked which Data Link you are going to be using. There is a folder called DataLinks
where Rave has been installed, containing some files with the .rvd extensions,
responsible from the connection mechanism. By default, you can choose between
BDE, DbExpress and ADO. I'll be using BDE for this example. Choose BDE, press
Finish, and the Database Connection Parameters window will show up. Every Data
Link has a different set of connection parameters available, similar to those
available in the Delphi IDE. For now, just set Alias to DbDemos and press OK.
Notice that a Database object has been added to the Project Treeview, under
Data View Dictionary:
Notice that the settings you configured in the Database Connection
Parameters, after the wizard, including username and password, if aplicable,
were saved in the AuthDesign property of the Database component. In the AuthRun
property you can use different settings to be used at runtime, when your report
has been deployed.
We are going to create now the Driver Data View. Click on New
Data Object, then choose Driver Data View. You should now choose
the Database Connection that is going to be used by this Data View: choose the
Database created in the previous step. A Query Avanced Designer will show up.
Drag and Drop the table customer.db from the table list to the Layout window.
It should look like this:
If you have more than one table, you should drag and drop fields that should
be joined between tables. If you press the Editor button you
can check the generated SQL, or type-in a more complex query. Let's keep the
simple Customer Listing for now. Press OK and a DriverDataView will be added
to the Project Treeview, below the Database components, having the selected
fields as subitems:
Notice that I renamed the Database Connection and the Data Viewto
more appropriate names. It's in the Treeview where properties of the fields
should be set, like the Display Label (FullName property),
and the DisplayFormat.
Report components that should be printed in a fixed position
in every page, like fixed headers and footers can be put directly in page. Components
whose position will be dependent of previously printed items, should be put
in bands. DataBands will be printed once for every record in the linked DataView,
while regular Bands will only be printed once, regardless of how many records
have been selected. Both can contain Data-Aware components (like DataText),
or regular components (like Text).
Bands should be put inside Regions. Regions delimitate the width
of the bands, and the maximum height that bands can use before starting a new
page. One page can have many Regions, and one Region can contain many Bands.
Add a Region to the Page covering its whole area. Inside the
region add a Band, to be used as the report header, a DataBand, to print the
customer information, and another Band, the report footer.
If you wish to change the ordering of existing bands in a
report, use the Move Forward and Move Behind
buttons in the Aligment Toolbar.
Rename the bands to more meaningful names (I used Header, CustomerData
and Footer). Set the DataView property of CustomerData to DvCustomer,
and set CustomerData as the ControllerBand of the Header and
Footer bands. You should also run the Band Style Editor, from the Object Inspector,
and set the Print Location of those two bands to Body
Header and Body Footer, respectively. You can have
an idea on how the report is going to be printed observing the Band Display
as you change the settings. It shows iterating bands repeated three times, and
other bands only once:
We also want the Header to be printed in other pages in case
the listing spans more than one page: check the New Page option
in the Print Occurrence groupbox, in that same dialog.
The Footer band will only print when DvCustomers
has reached its end. If you want it printed in every page, regardless of that,
just put the components directly on the page, below the region, and not in a
In the editor, you can quickly identify the
relationship between bands, their styles and their print occurrences:
It's not hard to add fields to a report. You
can Ctrl+Drag the fields from the DataView, in the Project
Treeview, to add DataText components to the report, and Alt+Drag
them to add Text components containing the Fullname property. This allows you
to quickly create the layout of the report. Now add some fields to CustomerData
and their title to the Header. I added CustNo, Company, Phone, TaxRate and LastInvoiceDate.
Don't forget that you can use the tools on
the Alignment Toolbar to align the components, even if they are in different
I added a title to the Header band and a simple text to the
Footer band, indicating that the listing has ended. Later on the series we are
going to see how to use the CalcOp and CalcTotal components to be able to add
totals, averages and other calculated values to the Footer.
To add this report to your project you should use use the same
approach as seen in Part II: just use a RvProject in a Form or DataModule, link
it to the report file, and call it's Execute method. But there is one gotcha
when using Driver Data Views: your application must load the apropriate driver.
To do that, just add the unit RvDLBDE to your uses clause, if using BDE, RvDLDBX
if using DbExpress, or RvDLADO if using ADO.
This article has shown how to develop simple DataAware reports. You can find
a project containing the report developed here on CodeCentral.
Part IV will demonstrate the use of Direct Data View, show how to make Master/Detail
reports, and how to calculate values to display totals and calculated fields.
Could not retrieve comments. Please try again later.
Download Delphi 10 now!
Webinars on demand!
More social media choices:
Delphi on Google+
@RADTools on Twitter
Server Response from: ETNASC04