Using RPX Files as Main Reports and Subreports


04-23-2003, 3:38 PM

RPX files are standard XML files. RPX is the Data Dynamics extension for any ActiveReport that is saved in XML format.

Any ActiveReport can be saved as an RPX file. This file can then be loaded into any EXE or DLL at run time and a report can be created and even exported if necessary from this XML file. Because of this you do not have to recompile an EXE or DLL every time you need to change a report. You only need to update the RPX file.

Example

Public Function GenerateReport() as ActiveReport
   dim rpt as new ActiveReport rpt.loadlayout app.path & "\report1.rpx"
   GenerateReport = rpt
End function

When you save a report in XML format all of the report layout information gets saved to XML but what about code? Code also gets saved through to Data Dynamics script editor. Of course you cannot export Visual Basic code to XML because Visual Basic code must be compiled to run. So Data Dynamics added the script editor to ActiveReports 2. The script editor allows you to write VBscript or Javascript for each of the events in ActiveReports. This code can then be saved with the report layout to XML format.

On top of this you can actually load a main report from XML that has a subreport/s that can also be loaded from XML.

This can be accomplished with a little help from a very powrful method of ActiveReports called AddNamedItem. AddNamedItem actually allows you to add any Visual Basic class to the scripting namespace of a report. This allows you to call compiled Visual Basic functions from any reports script. This is necessary if you wish to load a subreport into a mainreport, and both reports are being loaded from XML format.

Attached is a running sample demonstrating the correct way to use RPX files. The sample calls a COM object and generates reports that are loaded from XML format. The reports are then passed back to a calling EXE which displays the reports. Notice that there are no DSR files in the COM object. It generates all reports from RPX files. The main report contains a subreport and the sample makes use of AddNamedItem to load the subreport. To see how the subreport is being loaded look at the MainReports detail_onformat event and the AddNamedItem line of code in the GetReport function.