deleting a subreport at runtime
I have a subreport that I sometimes do not want included in a report. In
the past I just called FreeAndNil on the subreport component and
everything worked OK.
I have now switched to loading a report template, so instead of deleting
the subreport component that is declared in my form, I have to use
GetSubReports to get a reference to the subreport. When using this method,
if I free the subreport object it still gets referenced by report builder
later when the report is printing, and causes an exception.
Is there another way I can prevent the subreport from being included at
runtime?
TIA,
J.D. Mullin
Advantage R&D
--- posted by geoForum on http://delphi.newswhat.com
the past I just called FreeAndNil on the subreport component and
everything worked OK.
I have now switched to loading a report template, so instead of deleting
the subreport component that is declared in my form, I have to use
GetSubReports to get a reference to the subreport. When using this method,
if I free the subreport object it still gets referenced by report builder
later when the report is printing, and causes an exception.
Is there another way I can prevent the subreport from being included at
runtime?
TIA,
J.D. Mullin
Advantage R&D
--- posted by geoForum on http://delphi.newswhat.com
This discussion has been closed.
Comments
dataset component, a datasource, and at runtime I point my subreport to
this empty dataset. Not as elegant as I was hoping for, but it works for now.
J.D.
--- posted by geoForum on http://delphi.newswhat.com
Once the template has loaded, you could use a report object loop to gain
access to the subreport object, then either set its visibility to False and
DataPipeline to nil, or completely remove it from the report by freeing it.
Take a look at the following article on creating and using a report object
loop.
----------------------------------------------
Tech Tip: Loop Thru All Objects in a Report
---------------------------------------------
A ReportBuilder report is composed of a set of components. The basic
structure is
Reports.Bands[].Objects[]
The bands and objects within the report can be accessed directly by object
name or via the Bands and Objects array properties.
Below is an example of using the Bands and Objects array properties to
change the font for all objects on a report.
uses
ppClass;
procedure AssignFontToReport(aFont: TFont; aReport: TppCustomReport);
var
liBand: Integer;
liObject: Integer;
lObject: TppComponent;
begin
for liBand := 0 to aReport.BandCount-1 do
for liObject := 0 to aReport.Bands[liBand].ObjectCount-1 do
begin
lObject := aReport.Bands[liBand].Objects[liObject];
if lObject.HasFont then
lObject.Font := aFont;
end;
end;
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I have a pointer to the subreport TppReport object, but I wasn't able to
find out how to set its visiblity. I couldn't find a visible property or a
method to set visibility.
I use the following code to get the subreport:
reportFields.GetSubReports( oSubReports );
oTablePropReport := TppReport( oSubReports.Objects[0] );
I'm sure I'm missing something simple to change the visibility. Any help
would be appreciated.
Thanks for your time,
J.D.
--- posted by geoForum on http://delphi.newswhat.com
The GetSubReports routine gives you a handle to each TppChildReport object
(a TppCustomReport descendent and essentially the subreport design). Each
TppChildReport is tied to a TppSubreport object which is the actual
component you place on the main report. You will need to set the visibility
of this component rather than the actual Child Report. I would recommend
using a report object loop to gain access to the subreport object unless you
know the actual subreport you wish to render invisible.
----------------------------------------------
Tech Tip: Loop Thru All Objects in a Report
---------------------------------------------
A ReportBuilder report is composed of a set of components. The basic
structure is
Reports.Bands[].Objects[]
The bands and objects within the report can be accessed directly by object
name or via the Bands and Objects array properties.
Below is an example of using the Bands and Objects array properties to
change the font for all objects on a report.
uses
ppClass;
procedure AssignFontToReport(aFont: TFont; aReport: TppCustomReport);
var
liBand: Integer;
liObject: Integer;
lObject: TppComponent;
begin
for liBand := 0 to aReport.BandCount-1 do
for liObject := 0 to aReport.Bands[liBand].ObjectCount-1 do
begin
lObject := aReport.Bands[liBand].Objects[liObject];
if lObject.HasFont then
lObject.Font := aFont;
end;
end;
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com