Home General

Problem with dynamic subreports

edited August 2001 in General
I am using the procedure LoadSubReport at the end of this message to
dynamically load my existing reports into a single empty report as
subreports. The code works fine and the report runs as expected until I add
the following code to the OnPreviewFormCreate event of each existing report.

procedure TrmReport1.ppPage1PreviewFormCreate(Sender: TObject);
begin
(Sender As TppReport).PreviewForm.Windowstate := wsMaximized;
TppViewer((Sender As TppReport).PreviewForm.Viewer).ZoomSetting :=
zs100Percent;
end;

With this code, I get the following exception:

Project caodc4.exe raised exception class EReadError with message 'Error
reading ppPage1.onPreviewFormCreate: Invalid property value'.

I get the exception even with the code commented out in the
OnPreviewFormCreate event. Unfortunately, each of the existing reports are
run separately as well and the client has asked for them to open maximized
and zoomed so I need this ability. Is there a way around this?

Kevin Meier



*************** START CODE *****************
procedure TfrmMain.LoadSubReport(ReportClass: TppReport);
var
lSubReport: TppSubReport;
lMS: TMemoryStream;
begin
//create the report
lSubReport := TppSubReport.Create(frmMain);
lSubReport.Band := ppReport.DetailBand;// ppDetailBand1;

lSubReport.CreateReport(TppReport(ppReport.DetailBand.Report));
lSubReport.PrintBehavior := pbSection;
lSubReport.ParentPrinterSetup := False;

//load the report
lMS := TMemoryStream.Create;
try
ReportClass.Template.SaveToStream(lMS);
lMS.Position := 0;
lSubReport.Report.Template.LoadFromStream(lMS);
finally
lMS.Free;
end;

lSubReport.ResetPageNo := False;
end;
*************** END CODE *****************

Comments

  • edited August 2001
    > procedure TrmReport1.ppPage1PreviewFormCreate(Sender: TObject);

    Kevin:

    I do the exact same thing, and don't get the error, so I am guessing that
    something is wrong in a report.

    Is it possible that the OnPreviewFormCreate event is linked inside of one of
    the sub-reports? Load your report as ASCII and check it. Also, check the
    sender.classname ( you need to explicitly put this in the code, as it may
    not be avaiable in the debugger) in the OnPreviewFormCreate event.

    HTH,
    Ed Dressel
    Team DM
  • edited August 2001
    Thanks for the quick reply Ed. I was able to get around this by removing
    the OnPreviewFormCreate event from each report and creating it at runtime as
    required.

    Thanks.


This discussion has been closed.