Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

4 records in dataset but too many pages when printing

edited February 2009 in General
Hi, all,

I created the report with codes dynamically, not put components in the
form, and the ADOQuery loaded data from local file. There were 4 records
in the dataset, but when I previewed the report, it was blank, only
titles of the fields names were displayed. But when I tried to print
this blank report, there were too many copies to be printed, though I
set the copies:=1 before printing.

It would be OK when I put those compononets on a form.

What's the problem with my codes?

BR,

Jak


==========code snippets================

implementation
uses
ActiveX;

const
DataFile = 'Report.dat';
tmplReport = 'oi.rtm';
{ TReport }

constructor TReport.Create(const OrderNo: Integer);
begin
inherited Create;
FReportNo := OrderNo;
FADOQuery := TADOQuery.Create(nil);
FADOQuery.Connection := nil;
LoadData;
FDataSource := TDataSource.Create(nil);
FDataSource.DataSet := FADOQuery;
FReportDB := TppDBPipeline.Create(nil);
with FReportDB do
begin
DataSource := FDataSource;
AutoCreateFields := True;
OpenDataSource := True;
RangeBegin := rbFirstRecord;
RangeEnd := reLastRecord;
RangeEndCount := 0;
UserName := 'ReportData';
SkipWhenNoRecords := True;
end;
FReport := TppReport.Create(nil);
with FReport do
begin
DataPipeline := FReportDB;
LoadReport;
DeviceType := 'Screen';
PrinterSetup.Copies := 1;
PrinterSetup.PaperName := 'A4';
end;
DataLoaded := True;

//ShowMessage( IntToStr (
FReportDB.DataSource.DataSet.RecordCount ) );
// there are 4 records
end;

destructor TReport.Destroy;
begin
FReport.Free;
FReportDB.Free;
FDataSource.Free;
FADOQuery.Free;
inherited;
end;

function TReport.LoadData: Boolean;
begin
if FileExists(DataFile) then
begin
try
FADOQuery.Close;
FADOQuery.LoadFromFile(DataFile);
FADOQuery.Active := True;
Result := True;
except
Result := False;
end;
end
else
Result := False;
end;

function TReport.LoadReport: Boolean;
begin
if FileExists(tmplReport) then
begin
FReport.Template.FileName := tmplReport;
FReport.Template.LoadFromFile;
Result := True;
end
else
Result := False;
end;

function TReport.Print: Boolean;
begin
if not DataLoaded then
begin
LoadData;
LoadReport;
end;
try
FReport.Device := dvScreen;
FReport.PrintReport;
Result := True;
except
Result := False;
end;
end;

procedure TReport.PrintPreview;
begin
if not DataLoaded then
begin
LoadData;
LoadReport;
end;
FReport.Device := dvScreen;
FReport.Print;
end;

initialization
CoInitialize(nil);

finalization
CoUninitialize;
end.



--- posted by geoForum on http://delphi.newswhat.com

Comments

  • edited March 2009
    Hi Jak,

    Is your report properly connected to a DBPipeline? Are your DBTexts
    properly connected to the DBPipeline? Try building a similar report
    visually (no code), then take a look at the form source for the underlying
    code to give you hints on what you might be missing.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.