TFileRead()

TFileRead()

Read a file one line at a time

Syntax

      oFile := TFileRead():New( <cFileName> [, <nReadSize> ] )

Arguments

<cFileName> is the required name of the file to be read.

<nReadSize> is the optional size to use when reading from the file. The default value is 4096 and the allowed range is 1 through 65535. Any value outside of this range causes the default value to be used.

Returns

An instance of the File Reader class

Description

TFileRead() is used to access a file one line at a time. You must specify the name of the file when an instance of the class is created.

The class data should be considered private to the class.

The class methods are as follows:

New() Creates a new instance of the TFileRead class.

Open([<nFlags>]) Opens the file for reading. The optional nFlags parameter can use any of the FOPEN() flags from fileio.ch. The default is FO_READ + FO_SHARED. Calling this method when the file is already open causes the next ReadLine() to start over from the beginning of the file.

Close() Closes the file.

ReadLine() Returns one line from the file, stripping the newline characters. The following sequences are treated as one newline:

          1) CR CR LF; 
          2) CR LF; 
          3) LF; and 
          4) CR. 

          Note: LF CR is 2 newlines.

Name() Returns the name of the file.

IsOpen() Returns .T. if the file is open.

MoreToRead() Returns .T. if there are more lines to be read (think of it as an inverse EOF function).

Error() Returns .T. if an error has occurred

ErrorNo() Returns the current error code.

ErrorMsg([<cPre>]) Returns a formatted error message.

Examples

      PROCEDURE Main( cFile )
         LOCAL oFile := TFileRead():New( cFile )

         oFile:Open()
         IF oFile:Error()
            OutStd( oFile:ErrorMsg( "FileRead: " ) )
            OutStd( hb_eol() )
         ELSE
            DO WHILE oFile:MoreToRead()
               OutStd( oFile:ReadLine() )
               OutStd( hb_eol() )
            ENDDO
            oFile:Close()
         ENDIF
         RETURN

Tests

      See Examples

Compliance

This is a new Harbour Tools class

Files

Library is libmisc

Seealso

TClass()

Download a test program (File Copy)  (Test_TFR.prg).

Advertisements

2 responses to “TFileRead()

  1. Pingback: Harbour Classes | Viva Clipper !

  2. Pingback: Harbour All Functions – T | Viva Clipper !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s