Solved

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

Posted on 2001-06-15
4
189 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

11 Experts available now in Live!

Get 1:1 Help Now