How to modify RAP source code that is used in subreports
Hi,
In your Wiki is an example is given about how to modify RAP programs in
Code.
I have used this code, but it doesn't seem to work for code which is used to
calculate variables in sub-reports. I assume this information should be
found in lCodeModule.AllGlobalPrograms[liIndex].
However, in my example AllGlobalProgramCount = 4, but all code modules have
a nil value. It may have something to do with initialization, but I can't
find any documentation about this issue.
Thank you in advance,
Ruud Schneiders
In your Wiki is an example is given about how to modify RAP programs in
Code.
I have used this code, but it doesn't seem to work for code which is used to
calculate variables in sub-reports. I assume this information should be
found in lCodeModule.AllGlobalPrograms[liIndex].
However, in my example AllGlobalProgramCount = 4, but all code modules have
a nil value. It may have something to do with initialization, but I can't
find any documentation about this issue.
Thank you in advance,
Ruud Schneiders
This discussion has been closed.
Comments
For a subreport, you will want to initially get the code module of the child
report rather than the main report.
lCodeModule := raGetCodeModule(ppChildReport1);
{event-handlers}
for liIndex := 0 to lCodeModule.ProgramCount-1 do
begin
lProgram := lCodeModule.Programs[liIndex];
lsSourceString := lProgram.Source;
lsSourceString := StringReplace(lsSourceString, 'Hello', 'GoodBye',
[]);
{do something here to modify the source and then re-assign it to the
program}
lProgram.Source := lsSourceString;
end;
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks for your suggestion.
If took me some time to find out how to obtain the Childreports, but it
works.
The final code is as follows:
{Convert Subreports}
ppReport1.GetSubReports(MySubReportsList);
for MyIndex := 0 to MySubReportsList.Count-1 do Begin
MyChildReport := MySubReportsList.Objects[MyIndex] as
TppChildReport;
lCodeModule := raGetCodeModule(MyChildReport);
If Assigned(lCodeModule) then Begin
{event-handlers}
for liIndex := 0 to lCodeModule.ProgramCount-1 do Begin
lProgram := lCodeModule.Programs[liIndex];
lsSourceString := lProgram.Source;
lsSourceString := MyTranslateRap(lsSourceString);
lProgram.Source := lsSourceString;
end;
{global programs}
for liIndex := 0 to lCodeModule.AllGlobalProgramCount-1 do Begin
lProgram := lCodeModule.AllGlobalPrograms[liIndex];
If (lProgram <> nil) then Begin
lsSourceString := lProgram.Source;
lsSourceString := MyTranslateRap(lsSourceString);
lProgram.Source := lsSourceString;
End;
End;
End;
End;
Kind regards,
Ruud Schneidres
Excellent work.
Another approach would be to create a report object loop and use the
Subreport.Report property to retrieve the CodeModule.
http://www.digital-metaphors.com/rbWiki/Delphi_Code/Layouts/Report_Object_Loop
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
You might want to update the Wiki example... many have asked, why do the
fonts on subreports not get updated?
Add the test for TppSubReport and recursively call AssifnFontToReport
again...
if lObject is TppSubReport then
begin
with lObject as TppSubReport do
begin
AssignFontToReport(aaFont, report);
end;
end;
Walter
I just updated the article.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com