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

question about ModalPreview = false

edited November 2001 in General
Hi,

I have a question about ppReport.ModalPreview = false, I don't know why in
my app, I print a report like this:

procedure Form1.BtnPrintClick;
with TfrmPrintReport.Create(Self) do // create the form own the ppReport
begin
DefaultRptSetting(RptSettingRec); // setup some report setting
PrintClarityReport; // print the report
end

When I click the print button 4 times, it print the report 4 times and
create 4 viewers. It looks fine, but when I close the Form1, it will close
all the viewer at the same time. And sometimes it will raise an AV error.
Because my app is too big, I can't trace where the error happen. My app
use lots of RB units, such as
ppComm, ppRelatv, ppProd, ppClass, ppReport, ppTypes, ppViewr, ppDB,
ppDBPipe, ppModule, ppBands, ppCache, ppDevice,
ppCTDsgn, ppDsgner, ppUtils, myChkBox,
ppChrt, ppChrtDP,
raIDE, raCodMod,
daDatMan, daDataModule, daSQL, daQueryDataView, daIDE, daDataView,
daDBExonetDB,
and TXtraDev too.

I just can guess it maybe occur in here:

========================================================================
procedure TppCustomReport.Notify(aCommunicator: TppCommunicator; aOperation:
TppOperationType);

else if aOperation = ppopRemove then

if (FParentReport = aCommunicator) then
FParentReport := nil

else if (FTemplate.DatabaseSettings.DataPipeline = aCommunicator) then
FTemplate.DatabaseSettings.DataPipeline := nil;
========================================================================

But if I create a very very simple app - 2 Froms, one TDatabase, TQuery,
TppDBPipeline and a TppReport, do the same job, if I close the Form1, the 4
viewers still in there, will not automatic close by the Form1. It make me
very very confuse. Why in my app all viewers would be close by the
mainform, but doesn't in my test app.

Then I change my app code like these:

procedure Form1.BtnPrintClick;
with TfrmPrintReport.Create(Application) do // I change the owner is
Application
begin
DefaultRptSetting(RptSettingRec); // setup some report setting
PrintClarityReport; // print the report
end

Now my app work fine, don't have any AV error any more.

So I just want to know, when I set ppReport.ModalPreview = false, how RB
create the Viewer, who is the owner of the Viewer? And what should I aware
when I set ppReport.ModalPreview = false


Thanks

Tao

Comments

  • edited November 2001
    Hi Tao,

    you made a simple mistake, when calling 'Free' of any component (TComponent
    and all descendants), it is responsible for all owned component, therefore
    all owned components are freed first. (Object Pascal fundamental!)

    regards,
    Chris Ueberall;

  • edited November 2001
    But why I write a test program, I create 3 forms - Form1, Form2 and Form3.
    Form3 include a ppReport1

    In Form1,

    with TForm2.Create(self) do
    Show;

    In Form2,

    procedure Button1Click(Sender: Tobject);
    with TForm3.Create(self) do
    begin
    ppReport1.ModalPreview := false;
    ppReport1.Print;
    end;

    If I Click Button1 for 4 times, it create 4 viewers. And when I close
    Form2, all 4 viewers will not be free automaticly! But the Form2 should
    responsible for all 4 Form3 and free all 4 viewers. Is that right?

    I can send you my test program if you like.

    Thanks

    Tao


  • edited November 2001
    Hi Tao,


    either Form2 is not the owner OR it is not freed.
    You can check this by yourself, I second my last response, that's the way
    VCL-components work.


    no, thankyou, there is no need for.

    regards,
    Chris Ueberall;
  • edited December 2001
    I debug my sample app, yes, the owner of ppReport should be the Form1, not
    Form2, so form2 will not free the viewers

    Thanks for you help!


This discussion has been closed.