Composite Report

Hi,

I create a report into two forms in Delphi. The reports use the form Events to layout controls and others processes.

I create a composite report by this way:
myFormReport1.frxReport.PrepareReport(True);
            //
            myStream := TMemoryStream.Create;
            try
              myFormReport2.frxReport.SaveToStream(myStream);
              myStream.Seek(0, soFromBeginning);
              myFormReport1.frxReport.LoadFromStream(myStream);
            finally
              myStream.Free;
            end;
            //
            myFormReport1.frxReport.PrepareReport(False);
            myFormReport1.frxReport.ShowPreparedReport;

The first report is Ok but not the second because it can't call his events form.

Is there a solution to use the events of the second report's form?

If not, can I prepare the second report, save it and add it to the first ?

Thanks

Comments

  • Anu de DeusAnu de Deus Hampshire, UK
    edited 7:55PM
    When I need to merge 2 different reports, I actually copy the TfrxReportPage objects from one report into another, in code.
    Something like this:
          for i := 0 to fChildReport.PagesCount - 1 do
          begin
            // get a handle to the page to be merged
            if fChildReport.Pages[i] is TFrxReportPage then
            begin
              lPage := TFrxReportPage(fChildReport.Pages[i]);
              if lPage.visible then // I ignore non-visible pages
              begin
                // create new page, so it doesn't affect original components
                lNewPage := TFrxReportPage.Create(nil { fReport } );
    
                lPageText := ReportObjToText(lPage);  //<< my own function, just saves to a stream and then into a tstringlist to store it as a text.
               <lots of customizations can be done here>
                ReportObjFromText(lNewPage, lPageText);   << loads the new page object with the text contents of the previous one.
                lNewPage.name := NewRandomName << don't use .CreateUniqueName here, it's not good enough for this case
                fReport.InsertComponent(lNewPage);
              end;
         end;
    
    Now, that code is very simple, and work with very simple reports.
    However, some problems must be worked around, as you will need to load all datasources as well into the main report object (not shown in the code above).
    Also, you need to rename datasources and parameters that have the same name in all reports. And if you do that, you will have to update all the fields that reference them to use the new names.
    If you design your reports from the ground with unique names for everything, you will be free of most problems.
    I suggest you try the code above with simple reports without any use of datasources, just to see if it's applicable to you, then move forward step by step, by adding one datasource with only one memoview referencing it in the report.
    And by the way, if you have script code in your reports, you will have to find a way to merge them too. It can be done, because I did it.
    I hope it helps
  • edited 7:55PM
    Thank you for your answer. I will try.
  • edited January 2011
    Where I can find ReportObjToText() and ReportObjFromText() and what type is lPageText, please?
    Can you please put here these your functions?
    Thanks.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.