1. Tech

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To
Quick Reports Tutorial
Page 4: Band reports
 More of this Feature
• Page 1: Reports Overview
• Page 2: What's in a report
• Page 3: History of QR
• Page 5: Calculated fields
• Page 6: Sorting & Grouping
• Page 7: Label Reports
• Page 8: QR components
• Page 9: Without the QR
 Join the Discussion
"Post your questions, concerns, views and comments to this article..."
 Related Resources
• Reporting Tools
• Printing with TPrinter
• Controling MS Office

   Band reports

   Report Basics
I have found that there is a pattern you should follow when creating a Quick report. If you deviate from this pattern, you run the risk of confusing the program and not getting what you want. As always:

1. Create backups of your files so you can go to a previous version if you reach a dead end.

2. If you are working on a complex report you may want to use a test bed to handle your report. Here is a simple test bed I use:

Create a blank form with a button to call your report. On the button, insert this code:

procedure TForm2.Button1Click(Sender: TObject);
 var QRForm1: TQRForm1;
  Windowstate := wsMinimized;
  QrForm1:= TQrform1.Create(Self);
  Windowstate := wsNormal;

The Var should be a copy of the QR form you are testing. If you need to use a data module, then add it in your uses clause. Also add the report you are testing to the uses clause. Change the variables Qrform1 and QuickRep1 to the correct names of your report. I recommend keeping the QuickRep1 variable unchanged since it is only used within each quick report. Changing the form name should be enough to keep each report different in your mind.

   TIP #5
Use this template to call all your reports. It is simple to use and keeps the memory leaks to a minimum. If you want to go directly to printing a report, change the Preview method to Print instead. Once you have set up your environment, here are the steps used to create most simple Quick reports.

1. Create a new blank form. I like this better than using the QR template forms myself. Change the form name to something you can identify easily. If you use the convention of putting Rep in front of each report form's name such as 'RepCustSummary' you can keep the forms and reports separate easier.

2. Add a QuickRep component to the report. Right click to view the Settings dialog and use the Zoom out button to size the component so that you can see the whole form on the page. Change the page type and any other general report settings by selecting Report settings from the settings popup menu. At this time you should set the Report title property from the object inspector. This is necessary if you are printing the report on a network and the network needs a name to use for the temp output file.

   TIP #6
The report settings also lets you set the bands in the report, margins, number of columns and many other useful settings in one place. You can get to all these settings in the object inspector but this is a much nicer and more uncluttered way to view them.

3. Now you need to add the bands you are going to use. This is another area which can be confusing to QR if done in the wrong order. >From either the Bands subsection of the object inspector or the report settings dialog box, select which bands you will need:

Page Header band - Most reports need a band for column titles

Title band - Not needed for basic reports

Column Header - Not needed for most reports.

Detail band - Most reports have a band for the details of the report

Page Footer band - Not needed. You can use it if you want to put your page numbers there.

Summary Band - Not needed for basic reports.

As you select them they will appear on your form. If you were adding groups to your report you would now add them from the tool bar. See the section on using groups for more details.

4. You will usually need data for your report. If you are using a datamodule and haven't added it to your uses clause, do it now. The File menu option Use Unit makes this very easy. If you aren't using a datamodule, you will need to add a table component from the Data Access Tab of the Toolbar. Set the table's settings to the appropriate data table. The QuickRep component provides its own data source so you will not need to add one. Be sure to set the DataSet property of the QuickRep component to your table component (either from the Datamodule or your table component). If you don't do this, you will not see any data on your report. Set the Active property to true for now. You can do this programmatically if you want to later but doing it now will make things easier while you are in the design mode.

5. Place the fields you want to see in the order you want to see them. By holding down the shift key when you select the QRDBText component you can place several fields one after another. But I like to copy the first field after I modify it with the Dataset and any font changes I want. That way all you have to do is change the field name and rename the component. Renaming is optional in my opinion since you will see the field name in your field after you first preview it. The default field size is the size of the field name. This is because the Autosize property is set to true which means that the field will resize itself to the right as the size of the data changes. The left side is the anchor so your columns stay aligned. This can look confusing if the data in your field is smaller than the field name itself. If this is so, I recommend changing the Autosize property to false and setting the width manually.

6. Place the labels for your report columns. I usually place these labels in the Page header band. It Prints once at the top of the page. (See the section on Terminology for info on bands and how they work.) Because you do not know exactly where your fields will end but you do know where they begin, I recommend this method for placing your labels. First place your first QRLabel and change the font details the way you want. Don't try to manually position your label instead look at the left position property of the field this label is supposed to be positioned over and enter that number in the left position property of your QRLabel. This will automatically align the left sides of both components. Now Copy and Paste the rest of your labels changing the left property to match each field in your report.

   TIP #7
If you want the whole column underlined, (not just the words) put spaces after the words and set the underlined property of the Font. You can also create a pseudo centering effect by putting spaces in front of the words too. By modifying the Frame property you can also underline a column.

7. Place any calculated fields you need. Calculated fields can be created in the database table but it is usually easier to use a QRExpr component to do the work instead. It is important to realize that the component QRExpr has a property where the expression generated by the dialog actually sits. In some cases, you can simply enter or modify this line without having to go through the dialog process again and again. For more detail on this component see the section on Using calculated fields later in this tutorial.

8. Place any system fields you want. The default value for a QRSysdata component is Time. You will need to change this to whatever value you want to use. A nice feature of this component is the Text property, which places information about the system data such as 'Page No.'. If you want more space between the text and the data, simply add spaces after the words in the text.

During this process, I recommend that you use the preview option, which is found in the Quickreport component: Simply right click on the Quickrep component and select Preview. Having said this, the preview option does have limitations. First it does no calculations for calculated fields. Also it does not do any before print logic such as filtering. For this reason, using a stub program to launch your report is necessary if you want to see the real thing. One other basic tip: The band height determines the white space between each row. By selecting all the fields in a band and then aligning the tops, you get a uniform line. Now you can move them to the top of the band. Once they are there, you can adjust the band height to remove any white space you don't need.

Next page > Using Calculated fields > Page 1, 2, 3, 4, 5, 6, 7, 8, 9

All graphics (if any) in this feature created by Zarko Gajic.

 More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time.
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: Your application will be shut down!.
Access violations, invalid page faults, general protection faults; the name changes, but the nature of the problem is always the same. Find the solution to your Delphi AVs.
 Stay informed with all new and interesting things about Delphi (for free).
Subscribe to the Newsletter

 Got some code to share? Got a question? Need some help?

©2016 About.com. All rights reserved.