home *** CD-ROM | disk | FTP | other *** search
- TBrowse Paper Exercises
-
-
- SECTION 2
- ------------------------------------------------------------------------------
-
- 1. Using the source code file Tb02.prg as your starting point, add
- columns to show the current record number and the deleted flag.
-
- See Tbex01.prg
-
-
- 2. Modify the source code in Tb02 to ignore the up and down arrow keys.
-
- See Tbex02.prg
-
-
- 3. Add footing text to some of the columns using the TBColumn object's
- footing instance variable.
-
- See Tbex03.prg
-
-
- 4. If you have an EGA or VGA system, use Clipper's SetMode function to
- switch to an extended text mode, and set the TBrowse object's coordinates
- so it uses the entire display.
-
- See Tbex04.prg
-
-
- 5. Enclose Tb02's stabilize loop with Clipper's DispBegin / DispEnd
- functions.
-
- See Tbex05.prg
-
-
- 6. Modify Tb02 to set the TBrowse object's freeze instance variable to a
- 1. Pan the display right and left and note how the leftmost column
- is always visible. We cover the freeze instance variable in more detail
- in a subsequent section.
-
- See Tbex06.prg
-
-
- 8. Write a routine, TBframe, which accepts a TBrowse object as a parameter,
- and draws a box around it. Allow the user to pass an optional second
- parameter to specify the box type. The default should be a single line
- box.
-
- See Tbex07.prg
-
-
- SECTION 3
- ------------------------------------------------------------------------------
-
- 1. Program the K_F2 key to move the currently selected column one to
- the left. Program the K_F3 key to move the currently selected
- column one to the right. Program the K_F4 key to insert the
- currently selected column before the first column and freeze it.
- Program the K_F5 key to delete the current column. Display the
- keys and their functions in a status bar on the bottom row.
-
- See Tbex08.prg
-
-
- 2. Program the K_F6 key to offer the user a pop-up box of all the fields
- in the currently selected database. Use the Achoice and the Afields
- functions to do this. If the user selects a column, create a TBColumn
- object for it, and add it to the TBrowse object.
-
- See Tbex09.prg
-
-
- 3. Modify the routine from 3 above so the user can only select fields
- that are not already displayed. Use Achoice's parallel array of
- logicals to display currently displayed fields in a dim color; this
- also prevents the user from selecting them, of course.
-
- See Tbex10.prg
-
-
- 4. Write a function, TBCeval, much like Aeval and DBeval. It should take
- two parameters - a TBrowse object and a code block - and evaluate
- the code block once for each TBColumn object, passing the block a
- reference to the TBColumn object.
-
-
- FUNCTION TBCeval(oTbr, b)
-
- LOCAL nTbcNum
-
- FOR nTbcNum := 1 TO oTbr:colCount
- Eval(b, oTbr:getColumn(nTbcNum))
- NEXT
-
- RETURN NIL
-
-
- SECTION 4
- ------------------------------------------------------------------------------
-
- 1. Make some of the headings in Tb02.prg display on more than one line.
-
- This is easy. Just use ; characters in the heading string.
-
-
- 2. Use the defColor instance variable to display some columns in a different
- color from others.
-
- Just assign defcolor an array of two numbers.
-
-
- 3. Modify Tb02.prg to display negative AcBal fields in red, while
- showing others in the usual color.
-
- See Tbex11.prg
-
-
- 4. Modify Tb02.prg to use Clipper's Transform function to display
- telephone numbers with the usual formatting characters.
-
- Create the column like this:
-
- LOCAL oTbc7 := TBColumnNew("Work phone", ;
- {|| Transform(Wphone, "(999) 999-9999") })
-
-
- 5. Write a function, DbLookup, which accepts a database alias name as
- a parameter, and offers the user a pop-up box to select a record.
- The function should leave the database record pointer on the
- selected record. It should show all the fields and all the records,
- and should be general purpose. It should not change any global
- settings.
-
- See Tbex12.prg
-
-
- 6. Modify the program from 5 above to allow the programmer to pass an array
- defining the names of the fields to display.
-
- See Tbex13.prg
-
-
- 7. Using Tb02 as your starting point, change the code to display the
- entire row in red if the AcBal field is negative. Implement this
- after you have added all the TBColumn objects to the TBrowse object
- by setting the first TBColumn object's colorBlock instance variable,
- and then copying this to all the other TBColumn objects. Use TBrowse:
- getColumn to step through all the TBColumn objects.
-
- See Tbex14.prg
-
-
- SECTION 5
- ------------------------------------------------------------------------------
-
- 1. Modify Tb02 to sound the speaker if the user attempts to move past
- the start or the end of the data.
-
- Before the InKey(0), but after the stabilize loop, simply
- check the values of TBrowse:hitTop and TBrowse:hitBottom. If either
- is true, use the Tone() function to emit a sound.
-
-
- 2. Modify Tb02.prg to implement a status line on row 24. As the user is
- moving within the browse window, display the leftmost and rightmost
- visible column numbers, and the current column number.
-
- This is pretty straightforward. The source of your information is
- TBrowse:leftVisible, TBrowse:rightVisible, and TBrowse:colPos
-
-
- 3. Modify the program produced by 12 above so instead of displaying the
- left and rightmost column numbers, you display a right arrow character
- if there are more columns to the right of the rightmost column, and
- the left arrow character if there are more clumns to the left of the
- leftmost column.
-
- Again, this is easy. Just check whether TBrowse:leftVisible is
- > 1, and whether TBrowse:rightVisible is less than TBrowse:colCount.
-
-
- 4. Modify Tb02.prg to allow the user to lock columns using the + key,
- and unlock columns using the - key. The program must always lock
- columns at the left hand side of the display, regardless of which
- column is selected. Your code should ensure you never lock more
- columns than are visible, and you should never make the number of
- locked columns negative. Display the number of locked columns in
- the status bar on row 24.
-
- Just include the following entries in the CASE statement:
-
- #define K_PLUS 43
- #define K_MINUS 45
-
- ...
-
- CASE nKey == K_PLUS
- IF oTbr:leftVisible > 0
- oTbr:freezxe++
- ENDIF
-
- CASE nKey == K_MINUS
- IF oTbr:freeze > 1
- oTbr:freeze--
- ENDIF
-
-
- 5. Modify the code produced by 4 above to prevent the user from moving
- the highlight bar into a locked column.
-
- Include the following code before the stabilize loop:
-
- IF oTbr:colPos <= oTbr:freeze
- oTbr:deHilite()
- oTbr:colPos := oTbr:freeze + 1
- ENDIF
-
-
- 6. Modify Tb02.prg to use the colorRect method to display the entire selected
- row in the highlight color. You should dehighlight the entire row as
- soon as the user moves off the current record.
-
- See Tbex15.prg
-
-
- 7. The program by 6 above does not highlight the separator characters.
- Can you find a way of doing this?
-
- Heh, heh! What you must do is set TBrowse:colPos to an empty
- string, so there is no separator. Then, create a TBColumn
- object containing a block instance variable containing a space:
-
- oTbcSpace := TBColumnNew(, {|| " " })
-
- Then add this TBColumn object between the real TBColumn objects.
-
-
-
- SECTION 6
- ------------------------------------------------------------------------------
-
- 1. Modify MyBrowse2 so instead of passing arrays as parameters, you store
- the arrays right along with the object itself in its cargo instance
- variable.
-
- See Tbex16.prg. Call the routine with:
- MyBrowse2(oTbr, { aBeforeKeys, aAfterKeys })
-
-
- 2. Program a simple browse so you do not see deleted records. Program
- the Gray minus key to delete the current record (note you will have
- to tell the TBrowse object you changed something about the display).
- Confirm the deletion using the Alert function.
-
- See Tbex17.prg
-
-
- 3. Modify the program produced by 2 above so you can see deleted records.
- Program the Gray minus key to act as a toggle. If the record is not
- deleted, it deletes it. If it is deleted, it recalls it.
-
- See Tbex18.prg
-
-
- SECTION 8
- ------------------------------------------------------------------------------
-
- 3. Modify the DbLookup function you wrote in section 4, exercise 6,
- to implement an optional FOR and WHILE clause. You will need to
- pass the following six code blocks:
-
- bGoLast
- bGoFirst
- bWhile
- bFor
-
- See Tbex19.prg. Link it with Tbutils and Dict
-
-
- SECTION 10
- ------------------------------------------------------------------------------
-
- 1. In the 1-Many data entry code, we implemented the editing of newly
- added records inline. Modify this so the user can edit the records
- full screen, but still show them in the background a line at a time
- as the user adds records.
-
- See Tbex20.prg. Link it with Tbutils and Dict
-
-
- SECTION 11
- ------------------------------------------------------------------------------
-
- 1. Modify the TBrowse menu routine (Tb26.prg) to allow the user to scroll
- vertically in pull-down menus. Also implement pre and post selection
- code blocks. These should act much like WHEN and VALID clauses on GETs;
- the menu code evaluates the pre block before selecting the prompt,
- the post block on leaving the prompt. Use these to implement messages
- and automatic context sensitive help.
-
- See Tbex21.prg. Link it with Tbutils, Dict
-
-
- 2. Implement editing in the nested array browser (Tb23.prg). Consider
- using this to implement scrolling data entry screens. Load database
- fields into a nested array in any order you like, and then the user
- can move betwen them and edit them like GETs. If the user commits
- a change, replace the fields in the database. You can even use
- PgUp and PgDn keys to move to previous / next records like dBASE's
- EDIT command.
-
- See Tbex22.prg. Link it with Tbutils, Dict
-
-
- 3. The array returned by the select box routine (Tb25.prg) contained
- the selected record numbers in the order you selected them. Sort
- this array of record numbers based on a database field.
-
- The easiest way is to use Asort, and in the code block call a function
- passing two record numbers:
-
- Asort(aRecnos, {|nRec1, nRec2| Comp(nRec1, nRec2) })
-
- // Remember, this function must return a true if the two
- // are in order, otherwise a false. This version compares
- // the Lname fields
-
- // N.B. - if you are unfamiliar with using code blocks with asort
- // to sort arrays, refer to the principles paper
-
- FUNCTION Comp(nRec1, nRec2)
-
- LOCAL cTempLname
-
- DbGoTo(nRec1)
- cTemp := FIELD -> Lname
- DbGoTo(nRec2)
-
- RETURN cTemp < FIELD -> Lname
-
-
- 4. Implement a select box to select elements from an array. This is
- very easy if you use Tb25 as your base.
-
- Set the data movement code blocks to the usual ones to browse
- an array, and use Tb25 as a base. Change the selection code from:
-
- CASE nKey == K_ENTER
- RecSelect(aSelected, Recno())
- oTbr:refreshCurrent()
-
- To:
-
- CASE nKey == K_ENTER
- RecSelect(aSelected, i)
- oTbr:refreshCurrent()
-
- where i is the variable that maintains the array index
-
-
- 5. Implement a select box routine where you display selected rows
- in different colors from unselected rows.
-
- See Tbex23.prg. Link it with Tbutils, Dict
-
-
- 7. Browse a two-dimensional array where the first column contains a field
- name and the second column its contents. Consider using this for
- scrolling data entry input screens.
-
- See Tbex24.prg. Link with Tbutils, Dict, Tb07. We implemented
- PgUp to move to the previous record, and PgDn to move to the
- next record
-
-
- SECTION 12
- ------------------------------------------------------------------------------
-
- 1. Modify the file browsing code (Tb27.prg) to turn off the highlight
- bar. Then using the technique we showed in the tips and tricks section,
- change the key handling code so the display always scrolls when you
- press an arrow key.
-
- See Tbex25.prg. Link with Tbutils, Dict
-
-
- 2. Modify the file browsing code to allow the user to enter a string, and
- then display all lines containing that string in a different color
- from the other lines.
-
- See Tbex26.prg. Link with Tbutils, Dict