Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- FiveWin 1.9.2 - January 97 - <b>fivewin report engine - ii</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 FiveWin Report Engine - II
--------------------------------------------------------------------------------

    UNDERSTANDING THE REPORT OBJECT:

    You can access almost any part of the report if you understand how
    it works and how it is designed.

    The report object has a lot of data and methods that you should know
    and use.

    An object report has at least one object column, one object Line
    (for the title), one object device and if it has group(s), it will
    also have a Group object.

    The objects TRColumn, TRLine and TRGroup are the basis of the report
    engine.

    TRColumn holds all the columns of the report including its title,
    data, totals, etc.. (vertical object)

    TRLine holds all the lines wich go across the report from left to
    right. You can think of them as horizontal objects. These include
    Titles, Header and Footers.

    TRGroup holds all the information about each group defined in the
    report.

    You can manipulate the behavior of any object modifying its data or
    using some of its methods.

    Take a look at the classes data and methods. You will be impressed
    about all you can do. The only limit is your imagination.

    Examples:

    1) Change the TITLE font of column 3 to use the second font. Also
    because the column is multiline, change the picture of the second
    line to "999,999":

    LOCAL oColumn

    oColumn := oReport:aColumns[3]
    oColumn:bTitleFont := {|| 2}     // It's a block
    oColumn:aPicture[2] := "999,999"

    2) Left Justify the first line of the title using font 2
    and right justify the second line using font 3:

    #define LINE_LEFT     1
    #define LINE_RIGHT   2

    LOCAL oLine

    oLine := oReport:oTitle
    oLine:aPad[1]:= LINE_LEFT        // pad of line 1
    oLine:aPad[2]:= LINE_RIGHT       // pad of line 2
    oLine:aFont[1]:= {|| 2}          // font of line 1
    oLine:aFont[2]:= {|| 3}          // font of line 2

    As you can see, the object TRLine also holds multiple lines. That way
    the DATA is mostly arrays.

    3) On the footer of each group, print the current value of it and the
    counter of how many records have been included:

    GROUP ON Test->State ;
        FOOTER "Total State "+;
                oReport:aGroups[1]:cValue+ ;
                     str(oReport:aGroups[1]:nCounter)

    --------------------------------
    REP14.PRG

    GOING BACKWARDS:

    Just do a GO BOTTOM, change the way the Report does
    the skip, and change the while condition:

    USE TEST NEW
    GO BOTTOM

    REPORT oReport ....
         COLUMN ...
    END REPORT

    oReport:bSkip := {|| DbSkip(-1)}

    ACTIVATE oReport WHILE !Bof()

    -------------------------------
    REP15.PRG

    PRINTING ARRAYS:

    Use a static variable to hold the current array element and change
    the Skip block and While block.

    STATIC  nField

    Function Main()

         nField := 1

         REPORT oReport ....
         COLUMN ...
         COLUMN ...
         END REPORT

         oReport:bSkip := {|| nField++}

         ACTIVATE REPORT oReport ;
              WHILE nField <= len(aStructure)

    --------------------------------------
    REP16.PRG

    SHADOWS & GRIDS:

    There are two clauses that you can use when you create your columns:

    - SHADOW: This clause puts the background of a column in light gray.

    - GRID: This clause puts two lines vertically on both sides of a
      column.

    For example:

    COLUMN TITLE ... SHADOW GRID

    You can modify the type of grid, width and color. To do this you have
    to create the pens you need:

    COLUMN TITLE ... GRID <nPen>

    By default the pen used is black, solid, with a width of 1.

    The creation of pens is identical as for fonts. (Consult the Norton
    Guide for more information about pens.) For example:

    DEFINE PEN oPen WIDTH 5

    REPORT oReport PEN oPen
         COLUMN TITLE .... GRID 1
    END REPORT

    ACTIVATE REPORT

    -------------------------
    REP17.PRG

    CHANGING THE ASPECT:

    There is some DATA on the report objects that lets you change the
    aspect of the report, for example:

    - nTotalLine: Is the aspect for total lines. By default it is
      RPT_DOUBLELINE (2)

    - nGroupLine: Is the aspect for group lines. By default it is
      RPT_SINGLELINE (1)

    - nTitleUpLine: Is the aspect for the up lines in column titles.
      By default it is RPT_DOUBLELINE (2)

    - nTitleDnLine:  Is the aspect for the down lines in column titles.
      By default it is RPT_DOUBLELINE (2)

    - cPageTotal: Is a description for page total. By default it is ""

    - cGrandTotal: Is a description for grand total. By default it is ""

    - lSpanish: If .T. all the windows and dialogs are in Spanish.

    And also some methods like:

    - Margin(nValue,nType,nScale): This method lets you change the top,
      down, left and right margin of the report -- in inches or
      centimeters.

    Say(nCol, xText, nFont, nPad, nRow): This method lets you write the
    text you want on the report, indicating the column (where the column
    objects start), the text, the number of font to use, the number of
    pad(left, right, center) and the Row (by default the current row).

    ------------------------------
    REP18.PRG

    BITMAPS:

    To put a bitmap on your report is very easy. In the STARTPAGE clause,
    just make a call to a function of your own which draws the bitmap via
    the Saybitmap method() of the class TReport. An example:

    ACTIVATE REPORT oReport ;
         ON STARTPAGE Mybitmap()

    Function Mybitmap()

         oReport:SayBitmap(.3,.3,"ICO.BMP",.5,.5)

    RETURN NIL

    These are the parameters of the method Saybitmap:

    1) nRow
    2) nCol
    3) cBitmap file (only)
    4) nWidth
    5) nHeight
    6) nScale

    If Scale is in INCHES (1) then 1,2,4 and 5 are in inches, and if
    Scale is CMETERS (2) 1,2,4 and 5 are in centimeters.

    ------------------------------
    REP19.PRG

    BOXES & LINES:

    To put a box or a line on your report is very easy. On the STARTPAGE
    clause, just make a call to a function of your own which draws the
    line or box via the box or line method() of the class TReport. An
    example:

    ACTIVATE REPORT oReport ;
         ON STARTPAGE Mybox()

    Function Mybox()
         oReport:Box(.1, .1, 11.1, 7.6)
    RETURN NIL

    These are the parameters of the BOX method:

    1) nRow
    2) nCol
    3) nBottom
    4) nRight
    5) nPen
    6) nScale

    If nScale is in INCHES (1) then 1,2,3  and 4 are in inches, and if
    nScale is CMETERS (2) 1,2,3 and 4 are in centimeters.

    The fifth parameter is the number in the list of pens stated when
    you created the report.

    These are the parameters of the LINE method:

    1) nTop
    2) nLef
    3) nBottom
    4) nRight
    5) nPen
    6) nScale

    If nScale is in INCHES (1) then 1,2,3  and 4 are in inches, and if
    nScale is CMETERS (2) 1,2,3 and 4 are in centimeters.

    The fifth parameter is the number in the list of pens stated when
    you created the report.

    ---------------------------
    REP20.PRG

    PRINTING MEMOS:

    Printing memos on reports is sometimes a difficult job in other
    reporting systems, but is quite easy with the FiveWin Report Engine.

    Look how we do it:

    1) Create a column with empty DATA, but indicating the size (width
    of line in chars) that you want for the memo:

        COLUMN TITLE "Comments" DATA " " SIZE 50

    2) Create a function to be called by the ON CHANGE clause, like this:

    Function SayMemo()

     LOCAL nLines, nFor
     nLines := Mlcount(Test->Comment,50)

     /*
     Since ON CHANGE has caused the line to be incremented, we need to
     decrement the current line once.
     */

     oReport:BackLine(1)

     /*
     Now we can start the printing. But remember: before we print
     anything, we have to make a call to StartLine, and also afterwards
     a call to EndLine. This way the program controls the page breaks.
     */

     FOR nFor := 1 to nLines
        oReport:StartLine()
        oReport:Say(nMemoColumn , ;
             MemoLine(Test->Comment,50,nFor)
        oReport:EndLine()
      NEXT

    RETURN NIL

    And that is all there is to it.

    -------------------------------
    REP21.PRG

    PUTTING IT ALL TOGETHER:

    Just take a close look at the code for REP21.PRG.

    --------------------------------
    REP22.PRG

    ALL TOGETHER AND WITH COLORS!

       You can change the color of each font using the SetTxtColor method.

       SetTxtColor() receives two parameters. The first one indicates the
    nColor to use (see Colors.ch) and the second one the NUMBER of the
    Font in the report. For example:

                        oReport:SetTxtColor(CLR_HRED,1)

    You can also control the color of any Pens just by indicating their
    colors when you create them. For example:

           DEFINE PEN oPen COLOR CLR_BLUE

    If you want to change the color of the horizontal pen used in titles
    and totals, use the method SetPenColor.  For example:

                        oReport:SetPenColor(CLR_RED)

    You can also change the color of the shadows using the method
    SetShdColor(nNewColor), which by default is LIGHTGRAY.

    --------------------------------
    Rept23.PRG

    PRINTING FROM A .TXT FILE:

       In Rept23.PRG we are using the memo printing technique to print a
    text file.  This is very useful for quickly converting Clipper DOS
    reports to windows.

       For example, if your DOS application has reports created via the
    R&R Code Generator or Bandit, use that DOS report's option to have
    each report sent to a .TXT file.  Then adapt the simple code in this
    example to have FiveWin print the report's .TXT file.  Make sure that
    the font specified in this code matches the font used in the creation
    of the report. Guess what this means....you can convert each of your
    existing DOS reports to windows in 20 minutes each MAX, no matter how
    intricate they may be!

         Caveat: of course, whatever user interface screen code you have
    at the beginning of your DOS report .prg (for prompts/responses to
    specify various report options) will have to be converted to
    FiveWin GUI. Still quick -- after you establish a standard and
    adaptable format for your prompts/responses.

         NOTE: When previewing this report, until you zoom out it will
    appear garbled due to the use of the fixed pitch Courier font.  If
    you print it, it won't be garbled.

    ---------------------------------


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson