Solved

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

Posted on 2001-06-15
4
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

696 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