Use of Runtime Data Source with Visual Report Writer
by
, 29-Apr-2012 at 11:13 AM (111846 Views)
One of the new features of Visual Report Writer version 2.0 will be support of a Runtime Data Source (RDS). A runtime data source is a virtual table that is defined during report definition while the data is supplied via integration. This opens the way to report of data that does not come from a "real" database. In this blog you will read how to make a report based on the filelist.
Report Definition
Start Visual Report Writer and press Ctrl+N for a new report (or choose New Report from the file pull-down, click the New Report button). In the wizard that is now started you navigate to the page where you select the data source. Double click "Runtime datasource" or single click the tree item and click the Open button. Both of these actions opens a modal dialog in which you have to enter a table name - you can have multiple RDS tables in one report - and define the columns of the report. For each column select the desired data type and if required specify a length and precision. For the example to be made in this blog enter "Filelist" as the table name and the following column names;
Column Name Datatype Length Number Integer RootName String 40 DisplayName String 32 LogicalName String 31
After all columns are defined click the OK button. Click the table add button in the wizard page that you return to (the table appears on the right list). On the next page select all four columns to be printed. Skip the pages for grouping, selection. Decide on what paper format you want to print the report (for example A4 or Letter, Landscape or portrait).
On return in the designer format the report a bit so that the headers of the columns are printed bold. Click the preview button or press the key (F5) to see results. Visual Report Writer will open a dialog in which you can enter some test data. Test data is persistent to the report (it will be stored with the report). If you are happy with the results, save the report as filelist.vrw and continue to report integration via the Visual DataFlex Studio.
Integration
To integrate a Visual Report Writer report you need to attach the library that can be installed during the installation of Visual Report Writer to your workspace. After attaching the library you will see two new items in the new view/report page of the new component dialog in the Visual DataFlex Studio. From the new icons select the wizard to make a start with the integration.
In the wizard select the new report. If you wish you can preview the report to see if you have the right report. The wizard page where you can select the columns for record selection you better skip because you will provide the data yourself and in most cases - and certainly with the filelist report - it is more useful to supply not more data than is needed to be printed. You can opt in for a sort order but in most cases you will provide already sorted data. Finish the integration by selecting the desired preview style and other options on the options page.
In the source code you will find two routines that are RDS related. The first routine is LoadRDSData. This routine collects all the RDS tables of the report and sends out a message (named AddRDSData) to really load the data. The LoadRDSData does not only process the main report but also optional sub-reports. While it is not very likely that a report based on RDS uses a sub-report with RDS data it is possible and allowed BUT it is also possible that the main report is based on a "real" database such as Microsoft SQL server and a sub-report that uses RDS.
The AddRDSData routine gets the RDS table name as argument and a level. The level parameter is increased for each nested sub-report and can be used - if needed - to make a distinction between two RDS tables that carry the same name but are present in a different report. Normally the code inside AddRDSData only checks on table name and not on level. In the very rare situation that a report has two (or more) sibling sub-reports all using RDS as data-source and all using the same table names you need to make a code change yourself as it is not forseen by the wizard.
In the AddRDSData routine you find the CASE statement for your RDS tabke name. For this blog it is named 'Filelist'. For each table name the wizard writes code to help you start supplying the data. In comments you will find the name of each column, the data-type and the length. Our Filelist RDS data code needs to be:
The routine now creates a jagged array with data. The array size (the number of columns) need to match the table definition else the row will be rejected.Code:Function AddRDSData String sTableName Integer iLevel Returns Variant[][] Variant[][] vData Integer iRow Handle hTable Case Begin Case (iLevel = 0 and sTableName = "FileList") Get_Attribute DF_FILE_NEXT_USED of hTable to hTable While (hTable <> 0) Move hTable to vData[iRow][0] // Name: Number, Length: 10, Datatype: Integer Get_Attribute DF_FILE_ROOT_NAME of hTable to vData[iRow][1] // Name: RootName, Length: 40, Datatype: String Get_Attribute DF_FILE_DISPLAY_NAME of hTable to vData[iRow][2] // Name: DisplayName, Length: 32, Datatype: String Get_Attribute DF_FILE_LOGICAL_NAME of hTable to vData[iRow][3] // Name: LogicalName, Length: 31, Datatype: String Increment iRow Get_Attribute DF_FILE_NEXT_USED of hTable to hTable Loop Case Break Case End Function_Return vData End_Function
Now you can press F5 to compile and run the current project. The result should be your filelist in a preview window or in the desired output format.