home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 25.14. A file browser for small text files.
- 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
- */
-
- //───── NOTE: must compile with the /N option!
-
- function BrowText(filename)
- /*
- A general-purpose file browser for small text files.
- Pass a file name from DOS.
- */
-
- local textfile, lastLine, line, txt
-
- if filename = nil
- ? "Must specify a file name."
- return nil
- endif
-
- // Load the contents of the specified file.
- textfile := memoread(filename)
-
- // Determine how many lines are in the file.
- lastLine := mlcount(textfile)
-
- // A pointer used to keep track of which line we're on.
- line := 1
-
- @ 8, 19 say "File: " +filename
- @ 9, 19 to 21, 61
-
- // Create the browse object.
- txt := TBrowseNew(10, 20, 20, 60)
-
- // Add a column that displays a line of text.
- txt:addColumn(TBColumnNew(, ;
- { || memoline(textfile, 254, line)} ))
-
- // The data positioning blocks.
- txt:goTopBlock := { || line := 1 }
- txt:goBottomBlock := { || line := lastLine }
- txt:skipBlock := { |n| ArraySkip(lastLine, @line, n) }
-
- // Display the window and process navigation keystrokes.
- do while .t.
- do while .not. txt:stabilize()
- enddo
- if .not. Navigate(txt, inkey(0))
- exit
- endif
- enddo
- return nil
-
- // end of file CHP2514.PRG
-