REALbasic Printing Tutorial – On Target Reports

Note:  On Target Reports is no longer available for sale.  This is historical documentation.

Introduction

If you’ve been in the Visual Basic world you’ll probably have heard about Crystal Reports.  Crystal is THE reporting tool for the masses and, in fact, Microsoft includes Crystal Reports in every version of Visual Basic is sells.  Most VB developers looking at Real Studio notice the omission of a reporting tool right away.  While Real Software doesn’t include a reporting tool, there is a solution that will satisfy most needs.

On-Target Reports (sorry, it looks like they no longer have a web presence) is the only commercial reporting tool available for use with REALbasic.  As of this writing, version 4.2 of the professional version costs $199.95 and includes a set of classes so reports can be generated from within REALbasic applications.  It is written in REALbasic and connects to and queries from nearly any database that REALbasic supports.

The Project

We’ll take our project that we developed for the Graphic Object method and instead of using the primitive graphics object method we’ll use On-Target Reports.  Since the demo version of On-Target Reports won’t allow you to save a report we’ll include it in our project.

Download the Project File:  OnTargetReportsPrinting,zip

Creating the Report

When starting On-Target Reports you are given two options, create an new report or select an existing one.  We’ll create a new one.  This starts a new report wizard.  The first step is to select which type of database you’ll be using.  For this project we’re using the REALSQLDatabase and we’ll use the InventoryItems.sdb db we’ve already created.  Click the next arrow on the bottom right.

The next step is to select the tables you need in your report.  Since we only have one table we’re dealing with we’ll drag the Items table from the left listbox to the right one.  Click the next button on the bottom right.

The next thing to do is to select the fields you’ll want to display.  Again, drag the fields from the left listbox to the right one.  Once you’ve done that, click the next button on the bottom right.

The next step is to select grouping.  We’ll not be doing anything in this project so just click the next button.

The next step is to select the sorting you want for the report.  We’ll use the item name as the field to sort on so drag Items.sName from the left list to the right.  Select the next button to advance to the next stage.

The final step is to select record limits but we’ll skip this stage.  Click the finish button.

Up pops the actual report designer and its associated properties window.  On-Target Reports has five bands that the end user can mess with.

The Report Header band is what is show on the first page only.  By clicking on the blue Report Header band, the properties windows changes to accommodate the new properties.

The Page Header band is what is shown on each page.  One of the options is for this band to repeat on each page.  Make sure this is checked.

The Body band is where our repeating data is.

The Page Footer band is what is printed at the bottom of each page.  Notice that the wizard placed a date stamp (//) and page number stamp (##) on each page.

The Report Footer band is what is printed at the end of the report.  This area is useful for grand totals.

When the report designer is first opened after the wizard, you’ll immediately notice that it took a stab at putting in the fields we selected.  When it ran out of room it stopped putting fields in.  The column headers (in the page header band) are also the exact name of the fields as listed in the database and we’ll have to change them.  So click on each static text object and change the text in the properties window.  It’s a drag that you can’t do inline text editing.

We’ll also have to add the fields it didn’t add for us.  The only way I managed to do this was to duplicate an existing field and change the field from the properties window.  It’s a shame that there is no insert command.

To get our Gears ‘R Us graphic into the report, we can’t simply drag and drop our image into the report.  Instead we have to use the Add Image command from the File menu.  When we tried to use the Image tool from the toolbar, we could create an image object but we couldn’t figure out how to put an image in it.  In fact, we couldn’t delete the object until we clicked off of it and then back on.

The only piece left is to add a static text report title in the Report Header band.  Resize it so that it covers the entire width of the report and then make sure it’s center aligned in the properties window.  Our final version of the designer object looks something like this:

Make sure you save it and then quit.

REALbasic Programming

So far this report thing has been easy and On-Target Reports is just as easy when it comes to integrating into REALbasic.  If you drag and drop the On-Target Reports REALbasic Run Time classes directory into your REALbasic project you’re most of the way there.  Depending upon what database you’re using you might have to add some additional classes from the 4th directory.  In our case, we only had add the On-Target ReportsArrayRecordset class.  We’ll also add our own ReportPrinter class that implements the On-Target ReportsCompleteListener interface which is how we’ll know when operations are complete.  We copied this class from one of the sample projects provided.

The quick and dirty solution that we’re showing here is mostly handled in the apps open event.

We create a  new instance of our ReportPrinter class and pass in the report filename (located in the same directory as the application).  We then tell it to preview with our limiting sql statement.  In our case, we want to show all items where cost is greater than zero.  Up pops our preview report.

All the real work is done by the ReportPrinter class and allows a couple of different ways to pass in data.

We can view any page in the report as well as print the report from the toolbar at the top.  If you’re not a big fan of the button graphics, we believe you can replace them with your own.

That was simple!  Instead of the hours involved in getting the graphics object method working partially, we spent roughly 20 minutes getting On-Target Reports to do the same thing.  If your time is as valuable as ours then this is by far the easiest method of printing.

Conclusions

On-Target Reports is a fine addition to the arsenal of tools available for REALbasic.  It’s easy to use and a bargain at the price so there’s absolutely no reason NOT to use it for your simple reporting needs.

If you have a lot of simple reports this is the way to go.  Once you get familiar with the On-Target Reports designer you’ll be able to quickly design your reports.  It also makes it possible for your end users to format the reports they way they want them.

However, its designer applications error handling leaves much to be desired.  Experienced Crystal Reports developers will be disappointed in its lack of features.  As far as we can tell, there’s no way to do multiple columns, subreports or object introspection and property changes at run-time that Crystal lets you do.  Until something more feature rich appears for use with REALbasic, this is the reporting tool of choice.

If you feel that you would like to contribute to these articles or have comments or suggestions, please use our forum.