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

Creating "TppReport" objects as required

edited May 2009 in General
RB 10.07 Delphi 7

Hello

My reporting program needs to be able to show multiple reports simultaiously
so I create "TppReport" objects as required. I set the "ModalPreview"
property to false and everything appears to work fine.

My concern is that the object isn't being freed correctly when the user
closes the dialog. Is there anyway I can hook into an "OnClose" type event
to ensure everything is closed and freed. I tried connecting to the
"OnPreviewFormClose" event but it didn't fire when I closed the dialog. Here
is a code snippet of my creation process:

theCtrl := TppReport.Create (nil) ;
theCtrl.OnPreviewFormClose := ThePrintDialogClose ; <-- my event handler
that doesn't get called :(
theCtrl.ModalCancelDialog := false ;
theCtrl.ModalPreview := false ;

On a side issue, if I create the above object but pass in a reference to the
caller (eg Self), the objects seem to interfere with each other. Say I run
the same report twice, the first appears correct but the second will show
all the times as being the same and the time is the time I ran the first
report ! Obviously both reports should appear identical. As already stated,
if I use "nil" instead of "Self" they work fine.

Am I doing something wrong ?

Ian

Comments

  • edited May 2009
    > My concern is that the object isn't being freed correctly ...

    The following should free everything:

    theCtrl := TppREport.Create();
    try
    ...
    theCtrl.Print;
    finally
    theCtrl.Free;
    end;

  • edited May 2009
    That works for modal dialogs but as mine aren't it kills it as it starts to
    show it :(

    I guess I'll need to hold a reference of each in a list but I'd like a call
    back so I know when to remove it from the list.

    Ian


  • edited May 2009
    Hi Ian,

    Using your exact code below, the OnPreviewFormClose event fired as expected.
    I noticed that the name of your event is "ThePrintDialogClose"... do you
    perhaps want to implement the OnPrintDialogClose event instead?

    Note that you will not be able to free the report object directly from the
    OnPreviewFormClose event as it fires while the report is still closing. One
    option is to create a TTimer and use its event to free the report.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2009
    I got my event to fire but I had to set it in the "OnInitializeParameters"
    event. If I set it after I created the control it didn't get set (or was
    overwritten by a nil). I guess the "OnPreviewFormClose" event works when you
    drop the control on a form and set the event, but doing it all
    programmatically I need to wait for the control to build up its different
    elements first.



  • edited May 2009
    Hi Ian,

    I'm a bit unclear about what is happening. As I mentioned in my previous
    post, I copied your code exactly to the OnClick of a button and the event
    fired correctly. I did not drop a report on a form.

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