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:

  1. F2 Browser > select Contacts library > click New Class > click Report.
  2. Name the report class, rCountryList.
  3. Select rCountryList, press F8 to go to the class methods.
  4. Variables > Instance tab > add the following instance variables:

    Variable - iList
    Type - List

    Variable - iTitle
    Type - Character
    Subtype - 100
  5. Select the $construct report class method in the treelist.
  6. Add the following variables to the Parameters tab:

    Variable - pfList
    Type - Field Reference

    Variable - pTitle
    Type - Character
    Subtype - 100
  7. Add the following code to the $construct method:

    ; Copy the parameters to ivars.
    Calculate iList as pfList
    Calculate iTitle as pTitle

  8. Close the method editor to return to the F2 Browser.
  9. Double-click rCountryList to open the report class editor.
  10. 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
  11. Click anywhere on the report class editor and then press F3 to open the Component Store.
  12. Drag an Entry field from the component store to the middle line of the Page header section of the report class.
  13. With the entry field selected in the report class, press F6 to open the Property Mananger.
  14. Set the following properties of the entry field:

    General tab
    $dataname - iTitle
    $left - 1
    $width - 6

    Text tab
    $fontstyle - kBold
  15. Drag another Entry field from the component store to the middle line of the Record section of the report class.
  16. With the entry field selected in the report class, press F6 to open the Property Mananger.
  17. Set the following properties of the entry field:

    General tab
    $dataname - iList.CountryName
    $left - 1
    $width - 6
  18. 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.
  19. 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.
  20. 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.
  21. Drag another Entry field from the component store to the middle line of the Totals section of the report class.
  22. With the entry field selected in the report class, press F6 to open the Property Mananger.
  23. Set the following properties of the entry field:

    General tab
    $dataname - iList.CountryName
    $left - 1
    $width - 6
    $totalmode - kTmCount

    Text tab
    $fontstyle - kBold
  24. Click the Background Objects button in the F3 Component Store toolbar.
  25. Single-click the Line object in the Component Store to select the line drawing tool.
  26. 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.
  27. Select the line object in the Page Header section of the report class.
  28. 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.
  29. 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.

    rCountyList.gif

  30. 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.

  1. F2 Browser > select Contacts library > double-click wCountryList.
  2. Drag a Push button object from the F3 Component Store onto the BottomContainer scrollbox.
  3. With the pushbutton object selected set the following properties in the F6 Property Manager.

    General tab
    $name - Print
    $text - Print
    $left - 25
  4. Double-click the Print pushbutton object to get to the object's methods.
  5. Enter the following code in the $event method of the Print pushbutton object.

    On evClick
    If #SHIFT
       Breakpoint
    End If

    ; Set the current report class and report destination.
    Begin reversible block
    Set report name rCountryList
    Send to screen
    End reversible block

    ; Pass this window's list variable and title to the report's $construct method.
    Print report {(iList,$cinst.$title)}

Test the Report

We are ready to test the rCountryList report class.

  1. Contacts menu > select Countries menu line.
  2. Click the Print button.
  3. All going well the rCountryList report will be printed to the screen.