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

end-user data module create/free solution

edited June 2005 in End User
I am adding EndUser reporting to a working app, and need some advice. Thanks
in advance for any suggestions.

I have all report components neatly contained in one DataModule named "rm".
I was/am thinking it would be advantageous to create/free this as needed.

On the main form, a "print" button has the following event code:
begin
if not assigned( rm ) then
try
rm := Trm.create(nil);
except
on e:exception do ShowMessage('E in Report Init' + e.message);
end;
end;
-----------------------
Ok so far? Then in the "report" module...
------------------------
Trm.DataModuleCreate
begin
ActivateTables(true);
ReportExplorer.Execute;
end;
-------------------------
no problems yet...until we close the explorer
-------------------------
Trm.rbReportExplorerClose(Sender: TObject; var Action: TCloseAction);
begin
ActivateTables(false);
Action:=caFree; // should force call to destroy
end;
--------------------------
but it seems the ReportExplorer destroy method does not get called
(I set a break point to test it.)
--------------------------
Trm.rbReportExplorerDestroy(Sender: TObject);
begin
rm.free;
rm:=nil;
end;
---------------------------
...so the "report" module never gets freed & nil.

Obvious questions:
-Am I approaching this in the correct manner?
-Is it ok to free a component's form using the destroy method of one of the
form's own components?
-Is there something I am doing that would prevent the ReportExplorer destroy
method from being called?

thanks,

-monte

Comments

  • edited June 2005

    Do not call ReportExplorer.Execute from the DataModule.Create method.
    Instead add a TDataModule.ExecuteReportExplorer method that which calls
    ReportExplorer Execute. Also, rather than use the OnClose event to set
    caFree, simple free the datamodule.

    Here is a simple example....

    myDataModule := TmyDataModule.Create(nil);

    try
    myDataModule.ExecuteReportExplorer; // this will call ShowModal on the
    explorer form

    finally
    myDataModule.Free; // free the datamodule when the form closes
    myDataModule := nil;

    end;




    --
    Nard Moseley
    Digital Metaphors Corporation
    http://www.digital-metaphors.com


    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.