Clone Page
Hello,
I am trying to clone one page and then change something on the cloned page.
My goal is almost the same like https://www.fast-report.com/en/blog/show/same-reports-different-headers/ but I need it for Delphi. My progress so far is shown below.
//ClonedPage := TfrxReportPage.Create(Report1);
ClonedPage := TfrxReportPage.Create(nil);
ClonedPage.AssignAll(Report1.Pages[1]);
ClonedPage.CreateUniqueName();
for I := 0 to ClonedPage.AllObjects.Count - 1 do
begin
TfrxComponent(ClonedPage.AllObjects[i]).CreateUniqueName();
end;
//Report1.AllObjects.Add(ClonedPage);
If the page is created with owner Report1, the value of ClonedPage.AllObjects.Count is zero and the cloned page is blank. When I create it with nil owner, the Count of AllObjects is more than zero, but I cannot find a way to attach the page to the report to see if this method works.
Please, help!
Comments
G'day,
Have tried "inheritance"?
The Reports in our biggest Project are all based on inheritance from a Template Unit, and aTemplate FR3 File. All of the common functionality is in one Delphi Unit. This allows us to have a common look, feel and behaviour.
It gets a bit more complicated when we throw changes from Portrait to Landscape, Charts instead of Text, and Simple Reports vs. Composite ones.
But it works well and means we can quickly make global changes to reporting (e.g. content of page footers) as we as one-off / report-specific amendments (e.g. colour of alternating grid lines).
It does mean you need to set up for this from the start; it is a pain to convert an existing suite of reports to this approach. But I have done it - once!
Cheers, Paul
Hello, thanks for your response. I tried to use inheritance, but if I understood the concept correctly, it requires to use separate fm3 files. In my case this was a deal breaker. Anyway, I found solution for the problem, which took me at least 6 hours of trials and errors.
procedure DuplicateFastReportPages(aReport: TfrxReport);
var
lvTempPage, lvClonedPage: TfrxReportPage;
lvPageIndex, lvObjIndex : Integer;
begin
for lvPageIndex := 1 to aReport.PagesCount - 1 do
begin
lvTempPage := TfrxReportPage.Create(nil);
try
lvTempPage.AssignAll(aReport.Pages[lvPageIndex]);
for lvObjIndex := 0 to lvTempPage.AllObjects.Count - 1 do
TfrxComponent(lvTempPage.AllObjects[lvObjIndex]).CreateUniqueName(aReport);
//Add new page to the report
lvClonedPage := TfrxReportPage.Create(aReport);
lvClonedPage.CreateUniqueName(aReport);
lvClonedPage.AssignAll(lvTempPage);
finally
lvTempPage.Free;
end;
end;
end;
G'day,
Glad you worked out a solution that fits your requirements!
I expect the investment of "six hours of trial and error" will pay you back many times over. 🤓
Cheers, Paul