Solved

"D5 - QR3 How to create a dynamic report?"

Posted on 2001-06-15
4
191 Views
Last Modified: 2010-04-06
I am working with Delphi 5 and QReport 3.05.

I have a TQuery component which works as a datasource for a grid.

Now, I would like to include in my application only one QReport component, which attributes (title, columns, etc.) will change depending on the SQL string of the TQuery and the data displayed on the grid.

How can I include new fields (columns) on my report from my code??

For example, originally my TQuery brings back 2 fields (columns) "CountryCode" and "CountryDe", so QReport1.DetailBand will have 2 QRDBText components (one per column from the TQuery).

When I change my SQLString on my TQuery I will have different columns as result of it, how will I change the QReport1.DetailBand components to reflect the new columns from the TQuery??
0
Comment
Question by:miltonrodrigueza
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 6194491
Hi miltonrodriguez,

here is working sample:

QRDetails - details band.

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  Query1.Open;
  QuickRep1.PreviewModal;
  Query1.Close;
end;



// create components in runtime just after Query1 opens
procedure TForm1.Query1AfterOpen(DataSet: TDataSet);
var
  D: TQRDBText;
  I: Integer;
begin
  for I := 0 to Query1.Fields.Count-1 do
  begin
    D := TQRDBText.Create(QuickRep1);
    D.Parent := QRDetails;
    with D do
    begin
      DataField := Query1.Fields[I].FieldName;
      DataSet := Query1;
      AutoSize := False;
      Left := I * 50;
      Width := 50;
      Height := 20;
    end;
  end;
end;

// remove all components from detail band just after Query closed
procedure TForm1.Query1BeforeClose(DataSet: TDataSet);
begin
  while QRDetails.ControlCount > 0 do
    QRDetails.Controls[0].Free;
end;

------
Igor.
0
 

Author Comment

by:miltonrodrigueza
ID: 6198089
Igor,

The solution you provided me with works just fine!!!
Thanks a lot.

However, there is only one small detail, for some reason when I execute the preview of the report this does not display all records in the dataset (Tquery) instead it does only display info about the current record.

Any ideas what is causing this?? I would really appreciate a quick answer to this one since I am running out of time.

Thanks in advance.

Milton
0
 
LVL 9

Accepted Solution

by:
ITugay earned 75 total points
ID: 6199544
Hi Milton,

seems your forgot to assign QuikRep1.DataSet property to your TQurey.
Is it?

------
Igor.
0
 

Author Comment

by:miltonrodrigueza
ID: 6201443
Igor,

I am most definetly accepting your comment as the right answer. I am very much greatful for your help.

All the best,

Milton R.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ddeman not working in activex 3 94
Help on project with Soap 10 48
Performance of SQL statement 37 101
How to build JSON File in Delphi 6 3 17
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now