User Tools

Site Tools


asciifileclass_overview.htm
Navigation:  ABC Library Reference > ASCIIFileClass >====== ASCIIFileClass Overview C6H0009.jpg ====== Previous pageReturn to chapter overviewNext page

The ASCIIFileClass identifies, opens (read-only), indexes, and page-loads a file's contents into a QUEUE. The indexing function speeds any additional access of records and supports page-loading, which in turn allows browsing of very large files.

ASCIIFileClass Relationship to Other Application Builder Classes

There are several related classes whose collective purpose is to provide reusable, read-only, viewing, scrolling, searching, and printing capability for files, including variable length files. Although these classes are primarily designed for ASCII text and they anticipate using the Clarion ASCII Driver to access the files, they also work with binary files and with other database drivers. These classes can be used to build other components and functionality as well.

The classes that provide this read-only functionality and their respective roles are:

ASCIIViewerClass ASCIIFileClass plus user interface
ASCIIFileClass Open, read, filter, and index the file
ASCIIPrintClass Print one or more lines
ASCIISearchClass Locate and scroll to text

The ASCIIViewerClass is derived from the ASCIIFileClass. See ASCIIViewerClass for more information.

ASCIIFileClass ABC Template Implementation

The ASCIIFileClass serves as the foundation to the Viewer procedure template; however, the ABC Templates do not instantiate the ASCIIFileClass independently of the ASCIIViewerClass.

The ASCIIViewerClass is derived from the ASCIIFileClass, and the Viewer Procedure Template instantiates the derived ASCIIViewerClass.

ASCIIFileClass Source Files

The ASCIIFileClass source code is installed by default to the Clarion \LIBSRC folder. The ASCIIFileClass source code are contained in:

ABASCII.INC ASCIIFileClass declarations
ABASCII.CLW ASCIIFileClass method definitions

ASCIIFileClass Conceptual Example

The following example shows a sequence of statements to declare, instantiate, initialize, use, and terminate an ASCIIFileClass object and related objects.

This example lets the end user select a file, then display it's pathname, total line count, and the text at a given percentage point within the file.

PROGRAM

MAP

END

INCLUDE('ABASCII.INC')               !declare ASCIIFileClass

Percentile   BYTE(50)                 !a value between 1 & 100

GlobalErrors ErrorClass               !declare GlobalErrors object

AFile        AsciiFileClass,THREAD    !declare AFile object

FileActive   BYTE(False),THREAD       !AFile initialized flag

Filename     STRING(255),THREAD       !FileName variable

AsciiFile FILE,DRIVER('ASCII'),NAME(Filename),PRE(A1),THREAD

RECORD     RECORD,PRE()

Line        STRING(255)

          END

         END

window WINDOW('View a text file'),AT(3,7,203,63),SYSTEM,GRAY,DOUBLE

       PROMPT('Show Line at Percentile'),AT(5,4),USE(?Prompt:Pct)

       SPIN(@s3),AT(84,3,25,),USE(Percentile),RANGE(1,100)

       BUTTON('New File'),AT(113,2),USE(?NewFileButton)

       BUTTON('File Size'),AT(157,2),USE(?FileSizeButton)

       PROMPT('Line:'),AT(4,26),USE(?Prompt:Line)

       PROMPT(' '),AT(26,26,172,32),USE(?Line)

      END

CODE

GlobalErrors.Init                   !initialize GlobalErrors object

OPEN(window)

!Initialize AFile with:

FileActive=AFile.Init( AsciiFile, | ! file label,

            A1:line,  |             ! file field to display

            Filename,  |            ! variable file NAME attribute

            GlobalErrors)           ! GlobalErrors object

IF FileActive

 window{PROP:Text}=AFile.GetFileName()

ELSE

 window{PROP:Text}='no file selected'

END

ACCEPT                                                                                                            

 CASE FIELD()

 OF ?NewFileButton                           !on New File button

  IF EVENT() = EVENT:Accepted

   CLEAR(FileName)

   FileActive=AFile.Reset(FileName)          !reset AFile to a new file

   IF FileActive

    window{PROP:Text}=AFile.GetFileName()    !show filename in titlebar

   ELSE

    window{PROP:Text}='no file selected'

   END

  END

 OF ?Percentile                              !on Percentile SPIN

  CASE EVENT()

  OF EVENT:Accepted OROF EVENT:NewSelection

   IF FileActive                             !calculate lineno and get the line

    ?Line{PROP:Text}=AFile.GetLine(Percentile/100*AFile.GetLastLineNo())

   ELSE

    ?Line{PROP:Text}='no file selected'

   END

  END

 OF ?FileSizeButton                          !on File Size button

  IF EVENT() = EVENT:Accepted

   IF FileActive                             !display total line count

    ?FileSizeButton{PROP:Text}=AFile.GetLastLineNo()&' Lines'

   ELSE

    ?FileSizeButton{PROP:Text}='0 Lines'

   END

  END

 END

END

IF FileActive THEN AFile.Kill.               !shut down AFile object

GlobalErrors.Kill

asciifileclass_overview.htm.txt · Last modified: 2021/04/15 15:56 by 127.0.0.1