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

Multipage report and access violation

edited September 2006 in General
Hi,
I have some problems using the 2 page report and I don't know how to solve
it. The reports are being printed using TppReport component on a DataModule.
This component prints approximately 20 different reports and they get data
from around 10 different TDBPipelines, connected to ClientDataSets and
TSQLDataSets from MSSQL database. None of them has problems, even this
report, with which I have problemdoes not have any problems when printeed
separately. But when joined together, that's a problem.
So this report, named proracun.rtm has only detail band and two subreports,
let's name them report1pg and report 2pg. I have chosen for PrintBehavior
pbSection, but no datapipelines for both of them. Also I can't choose
anything for ShiftRelativeTo.
Report which loads in subreport report1pg is simple, it gets data from two
datasets, one for header and the second for other data. They are not
connected at all. Report no.2, which loads in subreport 2pg is master-detail
with header dataset (total 3 datasets). The master-detail datasets are
properly connected and the report works when run separately.
On combined report, the subreports use their own OnPrint events like this:

procedure TdmObracun.ppSubReport1pgPrint(Sender: TObject);
var
sReport : String;
begin
sReport := glSkupno.ProgramData.MapaReport; //global variable for reports
directory
sReport := IncludeTrailingPathDelimiter(sReport) + 'Proracun.rtm';
with TppSubReport(Sender).Report.Template do
begin
FileName := sReport;
LoadFromFile;
end;
end;

TppReport is run like this:

function TdmObracun.Print(APrintType: String): boolean;
begin
...
with ppRepObracun do
begin
Template.FileName := Trim(sReportFile);
Template.LoadFromFile;
AllowPrintToFile := True;
PreviewFormSettings.WindowState := wsMaximized;
PreviewFormSettings.ZoomSetting := zs100percent;
SavePrinterSetup := True;
//get the last printer settings from global variable
PrinterSetup.PrinterName := glSkupno.PrinterSetting.PrinterName;
PrinterSetup.BinName := glSkupno.PrinterSetting.BinName;
Print;
glSkupno.PrinterSetting.PrinterName := PrinterSetup.PrinterName;
glSkupno.PrinterSetting.BinName := PrinterSetup.BinName;
Result := True;
end;
...
end;

And when the report is being printed, for the first subreport OnPrint method
executes once, for the second subreport OnPrintMethod is executed twice and
after last execution I get Access Violation but the preview shows normally
and the combined report prints as expected. Any ideas? I am using RB 10.04
with Delphi2006.

Best regards,
Goran
Audax d.o.o.

Comments

  • edited September 2006
    Hi Goran,

    My guess is that the AV is occuring because you are trying to load a
    subreport again as it is already generating. The OnPrint event may be
    firing twice due to a page break or some other reason but in any case it is
    always a good idea to add some logic to critical code such as yours to check
    to multiple firings of an event (except for the OnCalc event of a
    TppVariable). Try adding some code to the OnPrint of the second subreport
    and be sure it only executes its code once per generation.

    --
    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.