Home arrow Delphi-Kylix arrow Page 4 - Creating Reports with Delphi and ADO
DELPHI-KYLIX

Creating Reports with Delphi and ADO


So far we’ve covered using ADO tables and queries with Delphi. And we have explored how to dynamically run a query at runtime. In this article we are going a stage further and discussing how to create reports from a database.

Author Info:
By: Jacques Noah
Rating: 5 stars5 stars5 stars5 stars5 stars / 12
October 16, 2006
TABLE OF CONTENTS:
  1. · Creating Reports with Delphi and ADO
  2. · ADO with Rave Reports
  3. · Building the application
  4. · Defining the Layout

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Creating Reports with Delphi and ADO - Defining the Layout
(Page 4 of 4 )

We still have to define the layout of the report. So, click on the rsys component and then go to the object inspectors events tab. Scroll down to the Onprint event and double click on it. Add the following code:

procedure TForm1.rsysPrint(Sender: TObject);
begin
with Sender as TBaseReport do begin
    NewLine;
    SetFont('Arial',18);
    FontColor := clRed;
    Print('Welcome to Code Based Reporting in Rave');
    NewLine;
    NewLine;
    ClearTabs;
    SetTab(0.2, pjLeft, 0.4, 0, 0, 0);
    SetTab(0.4, pjRight, 2.1, 0, 0, 0);
    SetTab(2.1, pjRight, 3.0, 0, 0, 0);
    SetTab(3.0, pjRight, 4.0, 0, 0, 0);
    SetFont('Arial', 10);
    Bold := True;
    PrintTab('Name');
    PrintTab('Surname');
    PrintTab('Age');
    PrintTab('Occupation');
    Bold := False;
    NewLine;
    q1.Open;
     q1.first;
    while not q1.Eof do begin
        Printtab(q1.FieldByName('name').Text);
        Printtab(q1.FieldByName('surname').Text);
        Printtab(q1.FieldByName('age').Text);
        Printtab(q1.FieldByName('occupation').Text);
          newline;
           q1.Next;
      if (LinesLeft < 3) and (not q1.Eof) then begin
        NewPage;
      end;
    end;
  end;
end;

This function basically prints a title and headers, and then the retrieved results. Lets start from the top. The first four lines deal with formatting and displaying the title of the report. The "Newline" phrase creates a space between whatever is on top and below. The "setTab" procedure does exactly what it says, it sets the positions of the text in the report. Here's how the procedure is declared in Delphi:

procedure SetTab(NewPos: double; NewJustify: TPrintJustify;
NewWidth: double; NewMargin: double; NewLines: byte; NewShade:
byte);

NewPos defines the starting position of the tab. If NewPos is set to the constant NA, then the tab will start immediately after the previous tab box.

NewJustify defines whether the tab is left (pjLeft), right (pjRight) or center (pjCenter) justified. If a non-zero width is given, then a tab box is defined and the text will be justified within the tab box rather than justified at the tab position.

NewMargin defines the distance between the tab box side and the text in hundredths of an inch.

NewLines uses the BoxLineXxxx constants to define where lines are to be drawn around the tab box.

NewShade defines the percentage of background shading to use for this tab box.

Before the "while" loop, the "PrintTab" procedure is used to print the headers for the report. Within the while loop, "PrintTab" creates dynamic text that prints out the results from the query. There is also a check that is made with in the loop:

      if (LinesLeft < 3) and (not q1.Eof) then begin

        NewPage;

      end;

This check is placed there to make sure that a new page is created when the end of the page is reached. The "LinesLeft" function will count the number of lines left on the page; if it is less then three lines, a new page is created.

Here's a result of this code:

Formatting the report

You can format the report even further to make it look more professional. For example you can set the background colors and a border. You can also use a more professional looking font, or make various other little changes. The possibilities are endless. Just keep in mind that the more formatting you want, the more code you need to add to make it happen. With a report that is Designer- based, you will not need to write a lot of code, and will therefore be able to do a lot more, much more quickly. But it has its downsides, which we will discuss in detail when I get around to writing the next article about Rave Reporting.

Conclusion

I have not gone into great detail about the Visual Designer, as it is a entire topic in itself, but what I've shown in this article should be enough for those of you who want to use Rave reports with ADO. At some point I will write an article specifically relating to Rave Report Visual Designer.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials