Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

916 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