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.
Next: Defining the Layout >>
More Delphi-Kylix Articles
More By Jacques Noah