home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a065 / 1.img / TBEXS.EXE / TBEX.TXT < prev    next >
Encoding:
Text File  |  1992-03-18  |  12.5 KB  |  393 lines

  1.                            TBrowse Paper Exercises
  2.  
  3.  
  4. SECTION 2
  5. ------------------------------------------------------------------------------
  6.  
  7. 1. Using the source code file Tb02.prg as your starting point, add
  8.    columns to show the current record number and the deleted flag.
  9.  
  10.    See Tbex01.prg
  11.  
  12.  
  13. 2. Modify the source code in Tb02 to ignore the up and down arrow keys.
  14.  
  15.    See Tbex02.prg
  16.  
  17.  
  18. 3. Add footing text to some of the columns using the TBColumn object's
  19.    footing instance variable.
  20.  
  21.    See Tbex03.prg
  22.  
  23.  
  24. 4. If you have an EGA or VGA system, use Clipper's SetMode function to
  25.    switch to an extended text mode, and set the TBrowse object's coordinates
  26.    so it uses the entire display.
  27.  
  28.    See Tbex04.prg
  29.  
  30.  
  31. 5. Enclose Tb02's stabilize loop with Clipper's DispBegin / DispEnd
  32.    functions.
  33.  
  34.    See Tbex05.prg
  35.  
  36.  
  37. 6. Modify Tb02 to set the TBrowse object's freeze instance variable to a 
  38.    1. Pan the display right and left and note how the leftmost column
  39.    is always visible. We cover the freeze instance variable in more detail
  40.    in a subsequent section.
  41.  
  42.    See Tbex06.prg
  43.  
  44.  
  45. 8. Write a routine, TBframe, which accepts a TBrowse object as a parameter,
  46.    and draws a box around it. Allow the user to pass an optional second
  47.    parameter to specify the box type. The default should be a single line
  48.    box.
  49.  
  50.    See Tbex07.prg
  51.  
  52.  
  53. SECTION 3
  54. ------------------------------------------------------------------------------
  55.  
  56. 1. Program the K_F2 key to move the currently selected column one to
  57.    the left. Program the K_F3 key to move the currently selected
  58.    column one to the right. Program the K_F4 key to insert the
  59.    currently selected column before the first column and freeze it.
  60.    Program the K_F5 key to delete the current column. Display the
  61.    keys and their functions in a status bar on the bottom row.
  62.  
  63.    See Tbex08.prg
  64.  
  65.  
  66. 2. Program the K_F6 key to offer the user a pop-up box of all the fields
  67.    in the currently selected database. Use the Achoice and the Afields
  68.    functions to do this. If the user selects a column, create a TBColumn
  69.    object for it, and add it to the TBrowse object.
  70.  
  71.    See Tbex09.prg
  72.  
  73.  
  74. 3. Modify the routine from 3 above so the user can only select fields
  75.    that are not already displayed. Use Achoice's parallel array of
  76.    logicals to display currently displayed fields in a dim color; this
  77.    also prevents the user from selecting them, of course.
  78.  
  79.    See Tbex10.prg
  80.  
  81.  
  82. 4. Write a function, TBCeval, much like Aeval and DBeval. It should take
  83.    two parameters - a TBrowse object and a code block - and evaluate
  84.    the code block once for each TBColumn object, passing the block a
  85.    reference to the TBColumn object.
  86.  
  87.  
  88.      FUNCTION TBCeval(oTbr, b)
  89.  
  90.      LOCAL nTbcNum
  91.  
  92.        FOR nTbcNum := 1 TO oTbr:colCount
  93.          Eval(b, oTbr:getColumn(nTbcNum))
  94.        NEXT  
  95.  
  96.      RETURN NIL
  97.  
  98.  
  99. SECTION 4
  100. ------------------------------------------------------------------------------
  101.  
  102. 1. Make some of the headings in Tb02.prg display on more than one line.
  103.  
  104.    This is easy. Just use ; characters in the heading string.
  105.  
  106.  
  107. 2. Use the defColor instance variable to display some columns in a different
  108.    color from others.
  109.  
  110.    Just assign defcolor an array of two numbers.
  111.  
  112.  
  113. 3. Modify Tb02.prg to display negative AcBal fields in red, while
  114.    showing others in the usual color.
  115.  
  116.    See Tbex11.prg
  117.  
  118.  
  119. 4. Modify Tb02.prg to use Clipper's Transform function to display
  120.    telephone numbers with the usual formatting characters.
  121.  
  122.    Create the column like this:
  123.  
  124.      LOCAL oTbc7 := TBColumnNew("Work phone", ;
  125.                                 {|| Transform(Wphone, "(999) 999-9999") })
  126.  
  127.  
  128. 5. Write a function, DbLookup, which accepts a database alias name as
  129.    a parameter, and offers the user a pop-up box to select a record.
  130.    The function should leave the database record pointer on the
  131.    selected record. It should show all the fields and all the records,
  132.    and should be general purpose. It should not change any global
  133.    settings.
  134.  
  135.    See Tbex12.prg
  136.  
  137.  
  138. 6. Modify the program from 5 above to allow the programmer to pass an array
  139.    defining the names of the fields to display.
  140.  
  141.    See Tbex13.prg
  142.  
  143.  
  144. 7. Using Tb02 as your starting point, change the code to display the
  145.    entire row in red if the AcBal field is negative. Implement this
  146.    after you have added all the TBColumn objects to the TBrowse object
  147.    by setting the first TBColumn object's colorBlock instance variable,
  148.    and then copying this to all the other TBColumn objects. Use TBrowse:
  149.    getColumn to step through all the TBColumn objects.
  150.  
  151.    See Tbex14.prg
  152.  
  153.  
  154. SECTION 5
  155. ------------------------------------------------------------------------------
  156.  
  157. 1. Modify Tb02 to sound the speaker if the user attempts to move past
  158.    the start or the end of the data.
  159.  
  160.    Before the InKey(0), but after the stabilize loop, simply
  161.    check the values of TBrowse:hitTop and TBrowse:hitBottom. If either
  162.    is true, use the Tone() function to emit a sound.
  163.  
  164.  
  165. 2. Modify Tb02.prg to implement a status line on row 24. As the user is
  166.    moving within the browse window, display the leftmost and rightmost
  167.    visible column numbers, and the current column number.
  168.  
  169.    This is pretty straightforward. The source of your information is
  170.    TBrowse:leftVisible, TBrowse:rightVisible, and TBrowse:colPos
  171.  
  172.  
  173. 3. Modify the program produced by 12 above so instead of displaying the
  174.    left and rightmost column numbers, you display a right arrow character
  175.    if there are more columns to the right of the rightmost column, and
  176.    the left arrow character if there are more clumns to the left of the
  177.    leftmost column.
  178.  
  179.    Again, this is easy. Just check whether TBrowse:leftVisible is
  180.    > 1, and whether TBrowse:rightVisible is less than TBrowse:colCount.
  181.  
  182.  
  183. 4. Modify Tb02.prg to allow the user to lock columns using the + key,
  184.    and unlock columns using the - key. The program must always lock
  185.    columns at the left hand side of the display, regardless of which
  186.    column is selected. Your code should ensure you never lock more
  187.    columns than are visible, and you should never make the number of
  188.    locked columns negative. Display the number of locked columns in
  189.    the status bar on row 24.
  190.  
  191.    Just include the following entries in the CASE statement:
  192.  
  193.      #define K_PLUS    43
  194.      #define K_MINUS   45
  195.  
  196.      ...
  197.  
  198.      CASE nKey == K_PLUS
  199.        IF oTbr:leftVisible > 0
  200.          oTbr:freezxe++
  201.        ENDIF
  202.  
  203.      CASE nKey == K_MINUS
  204.        IF oTbr:freeze > 1
  205.          oTbr:freeze--
  206.        ENDIF
  207.  
  208.  
  209. 5. Modify the code produced by 4 above to prevent the user from moving
  210.    the highlight bar into a locked column.
  211.  
  212.    Include the following code before the stabilize loop:
  213.  
  214.      IF oTbr:colPos <= oTbr:freeze
  215.        oTbr:deHilite()
  216.        oTbr:colPos := oTbr:freeze + 1
  217.      ENDIF
  218.  
  219.  
  220. 6. Modify Tb02.prg to use the colorRect method to display the entire selected
  221.    row in the highlight color. You should dehighlight the entire row as
  222.    soon as the user moves off the current record.
  223.  
  224.    See Tbex15.prg
  225.  
  226.  
  227. 7. The program by 6 above does not highlight the separator characters.
  228.    Can you find a way of doing this?
  229.  
  230.    Heh, heh! What you must do is set TBrowse:colPos to an empty
  231.    string, so there is no separator. Then, create a TBColumn
  232.    object containing a block instance variable containing a space:
  233.  
  234.      oTbcSpace := TBColumnNew(, {|| " " })
  235.  
  236.    Then add this TBColumn object between the real TBColumn objects.
  237.  
  238.  
  239.  
  240. SECTION 6
  241. ------------------------------------------------------------------------------
  242.  
  243. 1. Modify MyBrowse2 so instead of passing arrays as parameters, you store
  244.    the arrays right along with the object itself in its cargo instance
  245.    variable.
  246.  
  247.    See Tbex16.prg. Call the routine with:
  248.        MyBrowse2(oTbr, { aBeforeKeys, aAfterKeys })
  249.  
  250.  
  251. 2. Program a simple browse so you do not see deleted records. Program
  252.    the Gray minus key to delete the current record (note you will have
  253.    to tell the TBrowse object you changed something about the display).
  254.    Confirm the deletion using the Alert function.
  255.  
  256.    See Tbex17.prg
  257.  
  258.  
  259. 3. Modify the program produced by 2 above so you can see deleted records.
  260.    Program the Gray minus key to act as a toggle. If the record is not
  261.    deleted, it deletes it. If it is deleted, it recalls it.
  262.  
  263.    See Tbex18.prg
  264.  
  265.  
  266. SECTION 8
  267. ------------------------------------------------------------------------------
  268.  
  269. 3. Modify the DbLookup function you wrote in section 4, exercise 6,
  270.    to implement an optional FOR and WHILE clause. You will need to
  271.    pass the following six code blocks:
  272.  
  273.      bGoLast
  274.      bGoFirst
  275.      bWhile
  276.      bFor
  277.  
  278.    See Tbex19.prg. Link it with Tbutils and Dict
  279.  
  280.  
  281. SECTION 10
  282. ------------------------------------------------------------------------------
  283.  
  284. 1. In the 1-Many data entry code, we implemented the editing of newly
  285.    added records inline. Modify this so the user can edit the records
  286.    full screen, but still show them in the background a line at a time
  287.    as the user adds records.
  288.  
  289.    See Tbex20.prg. Link it with Tbutils and Dict
  290.  
  291.  
  292. SECTION 11
  293. ------------------------------------------------------------------------------
  294.  
  295. 1. Modify the TBrowse menu routine (Tb26.prg) to allow the user to scroll
  296.    vertically in pull-down menus. Also implement pre and post selection
  297.    code blocks. These should act much like WHEN and VALID clauses on GETs;
  298.    the menu code evaluates the pre block before selecting the prompt,
  299.    the post block on leaving the prompt. Use these to implement messages
  300.    and automatic context sensitive help.
  301.  
  302.    See Tbex21.prg. Link it with Tbutils, Dict
  303.  
  304.  
  305. 2. Implement editing in the nested array browser (Tb23.prg). Consider
  306.    using this to implement scrolling data entry screens. Load database
  307.    fields into a nested array in any order you like, and then the user
  308.    can move betwen them and edit them like GETs. If the user commits
  309.    a change, replace the fields in the database. You can even use
  310.    PgUp and PgDn keys to move to previous / next records like dBASE's
  311.    EDIT command.
  312.  
  313.    See Tbex22.prg. Link it with Tbutils, Dict
  314.  
  315.  
  316. 3. The array returned by the select box routine (Tb25.prg) contained
  317.    the selected record numbers in the order you selected them. Sort
  318.    this array of record numbers based on a database field.
  319.  
  320.    The easiest way is to use Asort, and in the code block call a function
  321.    passing two record numbers:
  322.  
  323.      Asort(aRecnos, {|nRec1, nRec2| Comp(nRec1, nRec2) })
  324.  
  325.      // Remember, this function must return a true if the two
  326.      // are in order, otherwise a false. This version compares
  327.      // the Lname fields
  328.  
  329.      // N.B. - if you are unfamiliar with using code blocks with asort
  330.      // to sort arrays, refer to the principles paper
  331.  
  332.      FUNCTION Comp(nRec1, nRec2)
  333.  
  334.      LOCAL cTempLname
  335.  
  336.        DbGoTo(nRec1)
  337.        cTemp := FIELD -> Lname
  338.        DbGoTo(nRec2)
  339.  
  340.      RETURN cTemp < FIELD -> Lname
  341.  
  342.  
  343. 4. Implement a select box to select elements from an array. This is
  344.    very easy if you use Tb25 as your base.
  345.  
  346.    Set the data movement code blocks to the usual ones to browse
  347.    an array, and use Tb25 as a base. Change the selection code from:
  348.  
  349.      CASE nKey == K_ENTER
  350.        RecSelect(aSelected, Recno())
  351.        oTbr:refreshCurrent()
  352.  
  353.    To:
  354.  
  355.      CASE nKey == K_ENTER
  356.        RecSelect(aSelected, i)
  357.        oTbr:refreshCurrent()
  358.     
  359.    where i is the variable that maintains the array index
  360.  
  361.  
  362. 5. Implement a select box routine where you display selected rows
  363.    in different colors from unselected rows.
  364.  
  365.    See Tbex23.prg. Link it with Tbutils, Dict
  366.  
  367.  
  368. 7. Browse a two-dimensional array where the first column contains a field
  369.    name and the second column its contents. Consider using this for
  370.    scrolling data entry input screens.
  371.  
  372.    See Tbex24.prg. Link with Tbutils, Dict, Tb07. We implemented
  373.    PgUp to move to the previous record, and PgDn to move to the
  374.    next record
  375.  
  376.  
  377. SECTION 12
  378. ------------------------------------------------------------------------------
  379.  
  380. 1. Modify the file browsing code (Tb27.prg) to turn off the highlight
  381.    bar. Then using the technique we showed in the tips and tricks section,
  382.    change the key handling code so the display always scrolls when you
  383.    press an arrow key.
  384.  
  385.    See Tbex25.prg. Link with Tbutils, Dict
  386.  
  387.  
  388. 2. Modify the file browsing code to allow the user to enter a string, and
  389.    then display all lines containing that string in a different color
  390.    from the other lines.
  391.  
  392.    See Tbex26.prg. Link with Tbutils, Dict
  393.