Home arrow Delphi-Kylix arrow Page 3 - 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 - Building the application
(Page 3 of 4 )

So without further ado, let's build a new application. Drop an ADO query (rename to q1) and from the Rave tab drop a TRvSystem (rename to rsys) component. Connect the ADO query component to the database using the connectionstring property. Refer to the previous articles if you don't know how to create a connectionstring. Then add a memo, a tedit box and a button. The memo is going to take our SQL statement and the tedit is going to take the parameter.

Your form should now look something like this:

Here's an example SQL statement:

Select * from person WHERE surname=:sname

q1.Parameters.ParamByName('sname').value:=edit1.Text;

The entire query is called a SQL statement. Notice the highlighted ":sname;" that is what we refer to as a parameter, which is like a variable. The value for the variable is given in the line "q1.Parameters.ParamByName ('sname').value:=edit1.Text;". In the previous article we hard coded this variable value as "Smith," but in this application we are going to make it more flexible by enabling you to enter a value in the edit box.

Why am I using the ADO query component? A query provides you with the means to interrogate a database to get any kind of information you want from it. For example, if you just want a list of all the people in the database who occupation is laborer, then a query would be able to extract that information for you. Most other ADO components don't do this. The application that is included in this article is specifically designed to enable you to have the flexibility to extract information from the database in whatever fashion you like.

Double click on the button and add the following code:

procedure TForm1.Button2Click(Sender: TObject);
begin
 q1.Close;
  q1.SQL.Add(memo1.lines.text);
  q1.Parameters.ParamByName('sname').value:=edit1.Text;
  q1.Open;
    RSys.Execute;
end;

What is happening here? This code does two things:

First it runs a query, which is defined in the memo and tedit and stores the results in the query component. Second, it runs the report system, by calling the execute method of the rsys component.


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 3 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials