Avatar of erwingosepa
erwingosepa

asked on 

How to print listview in quickreports

I have several listview's as ViewType vsReports , What I need is procedure that I can print or preview the listview in quickreports. using Delphi 7.
Delphi

Avatar of undefined
Last Comment
bokist
Avatar of bokist
bokist
Flag of Hungary image

Hi !

In main program (mainForm) you fill the listview with data.
Then create a form with quickreport on it.
 for example:
 in main:
     Application.CreateForm(TForm1, Form1);
     Form1.QuickRep1.Preview;
in report:
before.. implementation
  var
  Lw_count : integer;

procedure TForm1.QuickRep1BeforePrint(Sender: TCustomQuickRep; var PrintReport: Boolean);
begin
  Lw_count  := -1;
end;

procedure TForm1.QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
begin
  MoreData := Lw_count < mainForm.listview.items.count -1;
  inc(Lw_count);
end;

procedure TForm1.DetailBeforePrint(Sender: TQRCustomBand; var PrintBand: Boolean);
-- process :  mainForm.listview.items

Not tested- just from head.
worth to try.
Avatar of erwingosepa
erwingosepa

ASKER

I have listview in several forms, I want on procedure in the mainform that I can use all other forms.
an example will be perfect.
Avatar of bokist
bokist
Flag of Hungary image

Then forget quickrep1.onNeedData event.
Better use Query or AdoQuery to collect data from listview into some table.
Then use this table as input in QuickReport.
Avatar of erwingosepa
erwingosepa

ASKER

How do you add at runtime ADODataset or ADOQuery to quickReport. It should be a way that I can use the same procedure for all the form with different type queries in the ADO. The ADOQuery or Dataset should be input of this procedure,  Can you provide with a source code for example.
Avatar of bokist
bokist
Flag of Hungary image

This is brief example with BDE-Query-also not tested.

in Main program:

  with Query do
     begin
     Close;
     Sql.Clear;
     Sql.Add('CREATE TABLE [dbo].[xxx]');
     Sql.Add('  (country  varchar(30) null, town  varchar(30) null)');
     ExecSql;
     Close;
  end;

  with ListView do
    for i := 0 to Items.Count - 1 do    // do not forget subitems handling
       begin
       with Query do
          begin
          Close;
          Sql.Clear;
          Sql.add('Insert into [dbo].[xxx] (country,  town)');
          Sql.add('                 Values (  :c ,    '''')');
          Parambyname('c').asstring := Items[i].Caption;
          ExecSql;
          Close;
       end;
    end;
end;

in Report:

drop BDE Query on the form

in Object inspector
  set database name for Query
  set Quickrep1.Dataset  to  Query

procedure TForm1.FormCreate(Sender: TObject);
begin
   with Query do
      begin
      Close;
      Sql.Clear;
      Sql.add('select country, town from [dbo].[xxx]');
      Sql.add(' order by country, town');
      Open;
   end;
end.

procedure TForm1.DetailBand1BeforePrint(Sender: TQRCustomBand; var PrintBand: Boolean);
begin
   QRLabel1.Caption := Query.fieldbyname('country').asstring;
   QRLabel2.Caption := Query.fieldbyname('town').asstring;
end;
Avatar of erwingosepa
erwingosepa

ASKER

Let try it and let you know bokist
Avatar of erwingosepa
erwingosepa

ASKER

This will not work becuse the items need to created at runtime
ASKER CERTIFIED SOLUTION
Avatar of bokist
bokist
Flag of Hungary image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Delphi
Delphi

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

60K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo