I have a report that can go to the printer or to an output file. If it goes to the output file I only need to output the ppDBxxx components,no pplabels or lines etc. How can I scan the report and output only the data? Thanks
You can "scan" the report for certain components using a Report Object Loop. Then you will need to check if each component is DataAware by using the TppComponent.IsDataAware routine.
---------------------------------------------- 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.
Here is a code example to get the main report and all subreports:
procedure ReportObjectLoop; var slSubReports : TStringList; iSubReportCount : Integer; begin
AnalyzeReportObjects(ppReport1);
//Now handle the subreports, if any. slSubReports := TStringList.Create; //Get a list of all the Sub Reports ppReport1.GetSubReports(slSubReports); if slSubReports.Count > 0 then for iSubReportCount := 0 to slSubReports.Count - 1 do begin AnalyzeReportObjects((slSubReports.Objects[iSubReportCount]) as TppCustomReport); end; FreeAndNil(slSubReports); end;
procedure AnalyzeReportObjects ( oReport : TppCustomReport ); var iBandIdx : Integer; iObjIdx : Integer; begin with oReport do begin for iBandIdx := 0 to BandCount -1 do for iObjIdx := 0 to Bands[iBandIdx].ObjectCount - 1 do begin
Also, you can use a recursive version of the report object loop when you find a TppSubreport to pass the TppSubreport.Report object to the AssignFontToReport example method in the article.
Comments
You can "scan" the report for certain components using a Report Object Loop.
Then you will need to check if each component is DataAware by using the
TppComponent.IsDataAware routine.
----------------------------------------------
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.
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 not(lObject.IsDataAware) then
lObject.Visible := False;
end;
end;
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
this is great but seems to skip the subreports
procedure ReportObjectLoop;
var
slSubReports : TStringList;
iSubReportCount : Integer;
begin
AnalyzeReportObjects(ppReport1);
//Now handle the subreports, if any.
slSubReports := TStringList.Create;
//Get a list of all the Sub Reports
ppReport1.GetSubReports(slSubReports);
if slSubReports.Count > 0 then
for iSubReportCount := 0 to slSubReports.Count - 1 do
begin
AnalyzeReportObjects((slSubReports.Objects[iSubReportCount]) as
TppCustomReport);
end;
FreeAndNil(slSubReports);
end;
procedure AnalyzeReportObjects ( oReport : TppCustomReport );
var
iBandIdx : Integer;
iObjIdx : Integer;
begin
with oReport do
begin
for iBandIdx := 0 to BandCount -1 do
for iObjIdx := 0 to Bands[iBandIdx].ObjectCount - 1 do
begin
code....
end;
end;
end;
Regards,
Chuck Van Acker
Also, you can use a recursive version of the report object loop when you
find a TppSubreport to pass the TppSubreport.Report object to the
AssignFontToReport example method in the article.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com