Modeless Preview and Report Object Deletion
I'm trying to set up a small utility that will allow for multiple modeless
previews. The following sample code works just fine for loading the report
template and sending it to the screen:
procedure TForm1.NonModalPreview;
var
RBObj : TppReport;
begin
RBObj := TppReport.Create(nil);
RBObj.Template.FileName := 'TestReport.rtm';
RBObj.Template.LoadFromFile;
RBObj.DeviceType := 'Screen';
RBObj.ModalPreview := False;
RBObj.Print;
end;
The problem that I see is that the RBObj is never freed resulting in a
memory leak of about 16K for every print job sent to the preview window.
Does anyone have an example of how to use modeless previews with Report
Builder that doesn't result in a memory leak?
--
---------------------------------------
Terry Swiers
Millennium Software, LLC
http://www.1000years.com
http://www.atrex.com
Atrex Inventory Control/POS -
Big business features without spending big business bucks!
Atrex Electronic Support Options:
Atrex Knowledgebase: http://www.atrex.com/atrexkb.cfm
Email: mailto:support@atrex.com
previews. The following sample code works just fine for loading the report
template and sending it to the screen:
procedure TForm1.NonModalPreview;
var
RBObj : TppReport;
begin
RBObj := TppReport.Create(nil);
RBObj.Template.FileName := 'TestReport.rtm';
RBObj.Template.LoadFromFile;
RBObj.DeviceType := 'Screen';
RBObj.ModalPreview := False;
RBObj.Print;
end;
The problem that I see is that the RBObj is never freed resulting in a
memory leak of about 16K for every print job sent to the preview window.
Does anyone have an example of how to use modeless previews with Report
Builder that doesn't result in a memory leak?
--
---------------------------------------
Terry Swiers
Millennium Software, LLC
http://www.1000years.com
http://www.atrex.com
Atrex Inventory Control/POS -
Big business features without spending big business bucks!
Atrex Electronic Support Options:
Atrex Knowledgebase: http://www.atrex.com/atrexkb.cfm
Email: mailto:support@atrex.com
This discussion has been closed.
Comments
When you create an object with a nil owner, it will not be freed
automatically, you will need to free it yourself in code. Try using the
following method:
var
Report: TppReport;
begin
Report := TppReport.Create(nil);
try
Report.Print;
finally
Report.Free;
end;
end;
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
But if you change the example to the following, it hits the Report.Free call
immediately after sending the output to the screen which will either cause
an AV or remove the preview from the screen:
var
Report: TppReport;
begin
Report := TppReport.Create(nil);
Report.ModalPreview := False; //added
Report.DeviceType := 'Screen'; //added
try
Report.Print;
finally
Report.Free;
end;
end;
Will I need to create a management routine that keeps track of the Report
objects when they are printed to the screen and then delete the objects
manually after the preview is closed?
--
---------------------------------------
Terry Swiers
Millennium Software, LLC
http://www.1000years.com
http://www.atrex.com
Atrex Inventory Control/POS -
Big business features without spending big business bucks!
Atrex Electronic Support Options:
Atrex Knowledgebase: http://www.atrex.com/atrexkb.cfm
Email: mailto:support@atrex.com
Sorry about that, you can free the report object using the
OnPreviewFormClose event and a TTimer object to wait for the report engine
to finalize before freeing the Report object. Below is a small example I
made to demonstrate this. Hope this helps.
http://www.digital-metaphors.com/tips/FreeReport.zip
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com