Tips_tutorials   >   Studio101   >   Report Class
Report Class
In this section we will add a report class for printing a list of countries.
Create a Report Class
To create the report class:
- F2 Browser > select Contacts library > click New Class > click Report.
- Name the report class, rCountryList.
- Select rCountryList, press F8 to go to the class methods.
- Variables > Instance tab > add the following instance variables:
Variable - iList
Type - List
Variable - iTitle
Type - Character
Subtype - 100
- Select the $construct report class method in the treelist.
- Add the following variables to the Parameters tab:
Variable - pfList
Type - Field Reference
Variable - pTitle
Type - Character
Subtype - 100
- Add the following code to the $construct method:
Calculate iList as pfList
Calculate iTitle as pTitle
- Close the method editor to return to the F2 Browser.
- Double-click rCountryList to open the report class editor.
- Press F6 to open the Property Manager and set the following report class properties:
General tab
$islist - kTrue
$mainlist - iList
Sections tab
$pageheader - kTrue
$totals - kTrue
- Click anywhere on the report class editor and then press F3 to open the Component Store.
- Drag an Entry field from the component store to the middle line of the Page header section of the report class.
- With the entry field selected in the report class, press F6 to open the Property Mananger.
- Set the following properties of the entry field:
General tab
$dataname - iTitle
$left - 1
$width - 6
Text tab
$fontstyle - kBold
- Drag another Entry field from the component store to the middle line of the Record section of the report class.
- With the entry field selected in the report class, press F6 to open the Property Mananger.
- Set the following properties of the entry field:
General tab
$dataname - iList.CountryName
$left - 1
$width - 6
- Ctrl/Cmnd-click the empty line above the entry field in the Record section. The line should be hilited to indicate that it is selected.
- Ctrl/Cmnd-click the empty line below the entry field in the Record section. The line should be hilited to indicate that it is selected.
- Click the Delete lines button in the report class editor toolbar. The empty line above and below the entry field in the Record section should be deleted.
- Drag another Entry field from the component store to the middle line of the Totals section of the report class.
- With the entry field selected in the report class, press F6 to open the Property Mananger.
- Set the following properties of the entry field:
General tab
$dataname - iList.CountryName
$left - 1
$width - 6
$totalmode - kTmCount
Text tab
$fontstyle - kBold
- Click the Background Objects button in the F3 Component Store toolbar.
- Single-click the Line object in the Component Store to select the line drawing tool.
- Draw a horizontal line below the iTitle field in Page header section of the report class. After you have drawn the line object in the report class you can select it and drag the handles at either end of the line to change the line.
- Select the line object in the Page Header section of the report class.
- Ctrl/Opt+Drag the line object in the Page Header section of the report class to the first line of the Totals section. This should create a copy of the line in the Totals section.
- Ctrl/Opt+Drag the line object in the first line of the Totals section of the report class to the third line of the Totals section. This should create another copy of the line in the Totals section.
- Close the report class editor window.
Add a Print Button
We'll now add a Print button to the wCountryList window class. The Print button will be used to print the rCountryList report.
- F2 Browser > select Contacts library > double-click wCountryList.
- Drag a Push button object from the F3 Component Store onto the BottomContainer scrollbox.
- With the pushbutton object selected set the following properties in the F6 Property Manager.
General tab
$name - Print
$text - Print
$left - 25
- Double-click the Print pushbutton object to get to the object's methods.
- Enter the following code in the $event method of the Print pushbutton object.
On evClick
If #SHIFT
Breakpoint
End If
Begin reversible block
Set report name rCountryList
Send to screen
End reversible block
Print report {(iList,$cinst.$title)}
Test the Report
We are ready to test the rCountryList report class.
- Contacts menu > select Countries menu line.
- Click the Print button.
- All going well the rCountryList report will be printed to the screen.