Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 4 - Creating Reports with Delphi and ADO
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Creating Reports with Delphi and ADO
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 8
    2006-10-16

    Table of Contents:
  • Creating Reports with Delphi and ADO
  • ADO with Rave Reports
  • Building the application
  • Defining the Layout

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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.

       · I hope you found my article educational; I welcome your comments.
       · Hi!.I'm have programe writeln by kylix 3.0, beacause i want to printing some field...
       · Delphi 8 and higher now comes with a new reporting component called Crystal reports....
     

    DELPHI-KYLIX ARTICLES

    - 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...
    - Using the Client Dataset in Two-Tiered Clien...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT