home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP25.EXE / CHP2501.PRG < prev    next >
Encoding:
Text File  |  1991-06-12  |  2.5 KB  |  90 lines

  1. /*
  2.    Listing 25.1. A complete TBrowse-based database browser.
  3.    Author: Craig Yellick
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11. /*
  12.    MiniBrow.Prg:  A database browser implemented with a minimum
  13.    amount of code.
  14.  
  15.    Usage (from DOS):  minibrow datafile
  16.  
  17.    Compile with: /n /m
  18. */
  19.  
  20. #include "inkey.ch"
  21.  
  22. function Main(filename)
  23. local column, browse, key, n
  24.  
  25.   //  Check for a DOS command line parameter
  26.   if filename == nil
  27.     ? "Must specify a database filename."
  28.   //  Check that file exists.
  29.   elseif .not. (file(filename) .or. file(filename +".DBF"))
  30.     ? "File does not exist."
  31.  
  32.   //  Database checks out, clear screen and get down to it.
  33.   else
  34.     cls
  35.     //  Open the specified database.
  36.     use (filename) new
  37.  
  38.     //  Create a TBrowse object that knows how to deal with databases.
  39.     browse := TBrowseDB()
  40.  
  41.     //  Create a TBColumn object.
  42.     column := TBColumnNew()
  43.     //  Assign a data retrieval code block to the column object.
  44.     column:block := { || recno() }
  45.  
  46.     //  Add the record number column to the browse.
  47.     browse:addColumn(column)
  48.  
  49.     //  For each field in the current database...
  50.     for n := 1 to fcount()
  51.       //  Create a column object.
  52.       column := TBColumnNew()
  53.       //  Assign the column a code block that retrieves the field's value.
  54.       column:block := fieldblock(field(n))
  55.       //  Add the column to the browse.
  56.       browse:addColumn(column)
  57.     next n
  58.  
  59.     //  Keep looping as long as user wants to browse.
  60.     do while .t.
  61.       //  Keep looping until all rows in window have been displayed.
  62.       do while .not. browse:stabilize()
  63.         //  Allow user to interrupt by pressing a key.
  64.         if nextkey() <> 0
  65.           exit
  66.         endif
  67.       enddo
  68.  
  69.       //  Wait for a keystroke.
  70.       key := inkey(0)
  71.       //  Move the pointer based on user's keystroke.
  72.       do case
  73.       case key = K_UP      //  Up one row
  74.         browse:up()
  75.       case key = K_DOWN    //  Down one row
  76.         browse:down()
  77.       case key = K_LEFT    //  Left one column
  78.         browse:left()
  79.       case key = K_RIGHT   //  Right one column
  80.         browse:right()
  81.       case key = K_ESC     //  Done browsing
  82.         exit
  83.       endcase
  84.     enddo  //  While browsing
  85.     close database
  86.   endif  //  File exists
  87. return nil
  88.  
  89. // end of file CHP2501.PRG
  90.