home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 25.1. A complete TBrowse-based database browser.
- Author: Craig Yellick
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- /*
- MiniBrow.Prg: A database browser implemented with a minimum
- amount of code.
-
- Usage (from DOS): minibrow datafile
-
- Compile with: /n /m
- */
-
- #include "inkey.ch"
-
- function Main(filename)
- local column, browse, key, n
-
- // Check for a DOS command line parameter
- if filename == nil
- ? "Must specify a database filename."
- // Check that file exists.
- elseif .not. (file(filename) .or. file(filename +".DBF"))
- ? "File does not exist."
-
- // Database checks out, clear screen and get down to it.
- else
- cls
- // Open the specified database.
- use (filename) new
-
- // Create a TBrowse object that knows how to deal with databases.
- browse := TBrowseDB()
-
- // Create a TBColumn object.
- column := TBColumnNew()
- // Assign a data retrieval code block to the column object.
- column:block := { || recno() }
-
- // Add the record number column to the browse.
- browse:addColumn(column)
-
- // For each field in the current database...
- for n := 1 to fcount()
- // Create a column object.
- column := TBColumnNew()
- // Assign the column a code block that retrieves the field's value.
- column:block := fieldblock(field(n))
- // Add the column to the browse.
- browse:addColumn(column)
- next n
-
- // Keep looping as long as user wants to browse.
- do while .t.
- // Keep looping until all rows in window have been displayed.
- do while .not. browse:stabilize()
- // Allow user to interrupt by pressing a key.
- if nextkey() <> 0
- exit
- endif
- enddo
-
- // Wait for a keystroke.
- key := inkey(0)
- // Move the pointer based on user's keystroke.
- do case
- case key = K_UP // Up one row
- browse:up()
- case key = K_DOWN // Down one row
- browse:down()
- case key = K_LEFT // Left one column
- browse:left()
- case key = K_RIGHT // Right one column
- browse:right()
- case key = K_ESC // Done browsing
- exit
- endcase
- enddo // While browsing
- close database
- endif // File exists
- return nil
-
- // end of file CHP2501.PRG
-