?
Solved

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

Posted on 2001-06-15
4
Medium Priority
?
214 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 300 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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 this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

719 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