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

x
?
Solved

Quickreport and listview

Posted on 2000-02-15
18
Medium Priority
?
1,090 Views
Last Modified: 2013-11-22
Hi All ..

I made a project,
i have got qlabels , datailband...so on...
and i can read  data from database and put them in a listview but i can't transfer data from listview to quickreport ,
if you know the eazy way just tell :)

important = i want to transfer  data to qrlabel components,not qrdblabel
thanks .
0
Comment
Question by:albilgin
  • 9
  • 9
18 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 2522991
albiqin,

What do you want to have transported of the listview to the qrlabel?

The selected item ?

procedure TForm2.QuickRep1BeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
begin
  if form1.listview1.selcount > 0 then
    qrlabel1.caption := form1.listview1.selected.Caption;
end;

Do you want the text? The images? Both?

Zif
0
 

Author Comment

by:albilgin
ID: 2523101
nO not selected item .
all listview content ,
I want to transport text data in listview to qreport , only text.
 

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2523262
Hi albilqin,

this is a possible way (the first one I can think of right now) :


procedure TForm2.QuickRep1BeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
 var AllListItems : TStringList;
     i : integer;
begin
  with form1.listview1 do
  begin
    try
      AllListItems := TStringList.Create;
      for i:= 0 to Items.Count-1 do
      begin
        AllListItems.Add(Items[i].Caption);
      end;
      qrlabel1.caption := AllListItems.text;
    finally
      AllListItems.Free;
    end;
  end;
end;

Of course, code can be improved, eg. a TListview property in your QRForm class. When calling QRForm the form1.listview1 is assigned to this property. (This way you don't have to hardcode form1.listview1 in your QRForm) ... etc...

Regards, Zif
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:albilgin
ID: 2524656
Hi,ZifNab

you wrote that
qrlabel1.caption := AllListItems.text;
 
but this is not so eazy , just imagine
in delphi 4 when we go file then new and select business report , this wizard asks us that select your db then when we select then it makes a good and standart reporting, for example , in this wizard report it uses detail band and other reporting comps....,
In my project's report part, i want to use these detail band for scroll the data , but i don't want to use qrDBlabel,  just qrlabels, just forget about listview , focus on qrlabel and scroll of the data , is it clear  ?  
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2525049
no, not fully,

do you just want to fill in the qrlabel according to some data from a table?

procedure TForm2.QRBand1BeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
  if <condition> then qrlabel1.caption := 'blablabla';
end;

Zif.


0
 

Author Comment

by:albilgin
ID: 2526009
Adjusted points to 210
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2526293
albilgin,

can you give more info? I don't understand it fully.

You start from a database-table and you want to use detail-band? Or you want to use detail-band with what? Where do you get your data from? from the listview? What has to be on the detail-band?....

You want to use a detailband... with which data?? If you want to use a detailband you've somewhere to place a filter. The qrlabel (or qrdblabel) is just a component which shows a data-field (it doesn't scroll, nor filter your data)

Do you understand my confusion? Please, give more info.

More info please!

Tom.
0
 

Author Comment

by:albilgin
ID: 2526346
hi,

Just make a report using delphi wizard.
(file | new | businessreport ...)
How it shows the data ?
it show data from table1.first to table1.last
isn't it ?

and so i want to make a report like wizards did  but without using any quickreport's db component,
just forget listview ,

example
i have got text file with data , there are 5 rows ,and 7 columns,

and of course i have to use 7 qrlabels
and it have to scroll 5 times .. .

haw can i do this .. ??

 
0
 

Author Comment

by:albilgin
ID: 2526422
hi,

Just make a report using delphi wizard.
(file | new | businessreport ...)
How it shows the data ?
it show data from table1.first to table1.last
isn't it ?

and so i want to make a report like wizards did  but without using any quickreport's db component,
just forget listview ,

example
i have got text file with data , there are 5 rows ,and 7 columns,

and of course i have to use 7 qrlabels
and it have to scroll 5 times .. .

haw can i do this .. ??

 
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 840 total points
ID: 2527793
Ah,

then you need to use the OnNeedData method. Here a demo of it :

Drop a TitleBand and a DetailBand on the QR-form. Drop a QRLabel on the detailband.

{ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  :: QuickReport 3.0 for Delphi 3.0/4.0/5.0                  ::
  ::                                                         ::
  :: Demo report that is populated by the OnNeedData event   ::
  ::                                                         ::
  :: Copyright (c) 1995-1999 QuSoft AS                       ::
  :: All Rights Reserved                                     ::
  ::                                                         ::
  :: web: http://www.qusoft.com  fax: +47 22 41 74 91        ::
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: }
unit needdata;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, QuickRpt, Qrctrls;

type
  TfrmNeedData = class(TForm)
    QuickRep1: TQuickRep;
    DetailBand1: TQRBand;
    QRLabel1: TQRLabel;
    TitleBand1: TQRBand;
    QRSysData1: TQRSysData;
    procedure FormCreate(Sender: TObject);
    procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
      var PrintReport: Boolean);
    procedure QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
  private
    { Private declarations }
    SomeList: TStringlist;
    CurrentIndex: integer;
  public
    { Public declarations }
  end;

var
  frmNeedData: TfrmNeedData;

implementation

{$R *.DFM}

procedure TfrmNeedData.FormCreate(Sender: TObject);
var
  i: integer;
begin
  SomeList := TStringlist.Create;

  for i := 0 to 500 do
    SomeList.Add('Line ' + IntToStr(i));
end;

procedure TfrmNeedData.QuickRep1BeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
begin
  // You must reset your data in the BeforePrint event
  // or when you print from the preview, the report will
  // start with the last value(s)
  CurrentIndex := 0;
end;

procedure TfrmNeedData.QuickRep1NeedData(Sender: TObject;
  var MoreData: Boolean);
begin
  // If MoreData is true, then QuickReport will print
  // another detail band.  When you set it to false,
  // the report is done.  

  MoreData := (CurrentIndex < SomeList.Count);

  if MoreData then
  begin
    QRLabel1.Caption := SomeList[CurrentIndex];

    // Here's how to set the progress bar
    QuickRep1.QRPrinter.Progress := (Longint(CurrentIndex) * 100) div SomeList.Count;
  end
  else
    QuickRep1.QRPrinter.Progress := 100;

  Inc(CurrentIndex);
end;

end.

With the code I gave first and this demo, it is easy to use it with a listview.

For your code, just drop 7 qrlabels and fill them with the correct information. Set MoreData to true until you get to row 6.

Regards, Zif.
0
 

Author Comment

by:albilgin
ID: 2529213
thanks , it is working but

a new and last question :)

for example
i have got a listview with full of data
i want to start(gettext) at the top of the list view to the last of the listview

in database
we make simply
  table1.first ;
  table1.next ;
  table1.last;

how can i do these things in listview ?

thanks..
 
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2530374
Hi albilgin,

sorry that my comments are not so quick, but it looks that my notification doesn't work that good.

If we use the code :

with form1.listview1 do
  begin
      for i:= 0 to Items.Count-1 do
        begin
          AllListItems.Add(Items[i].Caption);
        end;
  end;

in the opening of QRForm. (and of course :
put a property of AllListItems : TStringlist; in the TQRForm declaration; and destory AllListItems (AllListItems.Free) at the closing of TQRForm.

Then we can use this list! and

Table1.First becomes AllListView.Strings[0]
Table1.Next becomes AllListView.Strings[i] (where i increments)
Table1.Last becomes AllListView.Strings[AllListView.Count-1]

Regards, Zif
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2530521
albilgin,

heh, same goes for using with TListView of course
(thus not using TStringList)  :

eg.

form1.ListView1.Items[0].Caption (=table1.First)
form1.ListView1.Items[i].Caption (=Table1.Next; by which 'i' each times increments by 1)
form1.ListView1.Items[ListView1.Items.Count-1].Caption (=table1.Last)

Zif.
0
 

Author Comment

by:albilgin
ID: 2534082
Hi zifnab;
Everything is ok except printing :(
I can fetch the data in listview  and i can transport them on quickrep preview
but when i press print button on preview page ,it doesn't work ..

i can't understand why .... help pleasee
Not=  there are no error on my quickrep ,
 
thanks
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2534260
Hi albilgin,

This works here :

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, QuickRpt, Qrctrls;

  type
   TfrmNeedData = class(TForm)
     QuickRep1: TQuickRep;
     QRLabel1: TQRLabel;
     TitleBand1: TQRBand;
     DetailBand1: TQRBand;
     procedure FormCreate(Sender: TObject);
     procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
        var PrintReport: Boolean);
     procedure QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
     private
      { Private declarations }
      SomeList: TStringlist;
      CurrentIndex: integer;
     public
      { Public declarations }
     end;

   var
    frmNeedData: TfrmNeedData;

   implementation

uses Unit1;

                      {$R *.DFM}

 procedure TfrmNeedData.FormCreate(Sender: TObject);
   var
    i: integer;
 begin
 end;

 procedure TfrmNeedData.QuickRep1BeforePrint(Sender: TCustomQuickRep;
   var PrintReport: Boolean);
 begin
   // You must reset your data in the BeforePrint event
   // or when you print from the preview, the report will
   // start with the last value(s)
   CurrentIndex := 0;
 end;

 procedure TfrmNeedData.QuickRep1NeedData(Sender: TObject;
   var MoreData: Boolean);
 begin
   // If MoreData is true, then QuickReport will print
   // another detail band.  When you set it to false,
   // the report is done.

   MoreData := (CurrentIndex < form1.ListView1.Items.Count);

   if MoreData then
   begin
    QRLabel1.Caption := form1.ListView1.Items[CurrentIndex].caption;
    // Here's how to set the progress bar
    QuickRep1.QRPrinter.Progress := (Longint(CurrentIndex) * 100) div form1.ListView1.ITems.Count;
   end
   else
    QuickRep1.QRPrinter.Progress := 100;
   Inc(CurrentIndex);
  end;

end.

If it still doesn't work, send me an email address to where I can send the full code

Regards, Zif.
0
 

Author Comment

by:albilgin
ID: 2534515
Hi ,
it still doesn't work .
everything is ok but it doesn't print..
but when i save it like *.qrp and then open and again try to print it works !
what is wrong ??

my e mail adress is albilgin@hotmail.com
my icq number is 21059142
thanks
0
 

Author Comment

by:albilgin
ID: 2534546
pardon !
:))
yes it is really working  :)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2534632
Glad I could help.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline
Suggested Courses

773 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