Solved

building report at run time...

Posted on 1998-12-01
5
468 Views
Last Modified: 2010-04-04
How to make report with quickreport in delphi 3 at run time ? Because I want to make report application that generate report which have colomn that equal with fields that selected in SQL command. Can I make TQRDBText component at run time and access all of TQRDBText's properties  ? Please, help me.. thank you very much..
0
Comment
Question by:whedhoest
  • 3
5 Comments
 

Author Comment

by:whedhoest
ID: 1348870
Edited text of question
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1348871
Hi whedhoest,

It's posible to create a TQRDBText component at runtime.
Something like this will get you started

var
  qrSomeField :TQRDBText;
begin
  qrSomeField := TQRDBText.Create(nil);
  qrSomeField.Dataset := yourDataset;
  qrSomeField.Datasource := yourDatasource;
  ...........
  ...........
  qrSomeField := nil;
end;

Sorry don't have the time right now to work this out in more detail, but this should get you in the right direction.

PS. if you like I will give it a better look at the other side of the day.


0
 
LVL 1

Accepted Solution

by:
Gerhard100198 earned 200 total points
ID: 1348872
This is not fully working code but it should be more than enough to get you up and going.
If you have any questions please feel free to ask.

You can also email me at gerhardvr@email.com

var
  I: Integer;
begin

  For I := 0 to NumberOfColumnsYouNeed do begin
    With TQRDBText.Create(Self) do begin
      //Now loop to create a QRDBText component for evey one of the fields in your query
      //I like to use the field name as the component name prefixed with some text, in
      //this case 'qr_'
      Name := 'qr_' + WhatEverTheFieldNameIs;
      Parent := TheFormNameItBelongsTo //Remember to set this else it won't be visible
      Top := YouCalculateTheTopPos;
      Left := YouCalculateTheLeftPos;
      ....... //You now have access to all the properties of the components
  end;

  //If you need to access any of these components at a later stage to change
  //a property you can do it in the following way
  With FindComponent('WhatEverTheNameOfTheComponentIs') do begin
     Visible := False;
  end;

  //REMEMBER TO FREE ALL THESE COMPONENTS THAT YOU HAVE CREATED
  //WHEN YOURE DONE
  For I := 0 to NumberOfColumnsYouNeed do begin
    //You have to do this for all the fields in your query since you created
    //a component for each of them
    With FindComponent('qr_' + WhatEverTheFieldNameIs) do begin
      Free;
    end;
  end;
end;
0
 
LVL 1

Expert Comment

by:Gerhard100198
ID: 1348873
Just had a look at Whedhoest comment.

What he suggests will work except that you don't know how many columns you're going to have at design time preventing you to declare the Field variables before compiling.

The way I suggest is in essence the same at that which Whedhoest suggests except that it allows you to create as many columns as you need at runtime. In this way you don't have to know how many variables you need to declare. As a matter of fact, because of the way the QRDBText components are created ( With TQRDBText.Create(Self) do begin) and accessed at a later stage
(With FindComponent('WhatEverTheNameOfTheComponentIs') do) you don't have to declare variables at all to store the component into.

The method used here makes it totally dynamic which is exactly what you are looking for.
0
 
LVL 1

Expert Comment

by:Gerhard100198
ID: 1348874
Need to correct the code I submitted in the answer:

Because FindObject return a TObject you will need to typecast the result to be able to get access to it's properties

Examle for the above code:

  With TQRDBText(FindComponent('WhatEverTheNameOfTheComponentIs')) do begin
          Visible := False;
  end;

AND

   With TQRDBText(FindComponent('qr_' + WhatEverTheFieldNameIs)) do begin
           Free;
   end;
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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

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

19 Experts available now in Live!

Get 1:1 Help Now