ASCIISearchClass Overview

Top  Previous  Next

The ASCIISearchClass provides the user interface--a persistent non-MDI Find dialog--to locate specific text within the browsed file. The ASCIISearchClass interface lets the end user specify the direction and case sensitivity of the search, and it allows repeating searches ("find next").

ASCIISearchClass Relationship to Other Application Builder Classes

The ASCIISearchClass relies on the ASCIIFileClass to read and index the file that it searches. It also uses the TranslatorClass to translate its Find dialog text if needed.

The ASCIIViewerClass uses the ASCIISearchClass to provide the end user with a Find dialog to locate text in the viewed file.

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

 

ASCIISearchClass

Print one or more lines

 

ASCIISearchClass

Locate and scroll to text

ASCIISearchClass ABC Template Implementation

Both the Viewer procedure template and the ASCIISearchButton control template generate code to instantiate an ASCIISearchClass object. The Viewer template accomplishes this by adding a parameter to the ASCIIViewerClass.Init method. The ASCIISearchButton template accomplishes this by declaring an ASCIISearchClass object and calling the ASCIIViewerClass.AddItem method to register the ASCIISearchClass object with the ASCIIViewerClass object.

ASCIISearchClass Source Files

The ASCIISearchClass source code is installed by default to the Clarion \LIBSRC folder. The specific ASCIISearchClass source code and their respective components are contained in:

 

ABASCII.INC

ASCIISearchClass declarations

 

ABASCII.CLW

ASCIISearchClass method definitions

ASCIISearchClass Conceptual Example

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

This example lets the end user select a file, then search and print from it.

MEMBER('viewer.clw')

 

INCLUDE('ABASCII.INC')

INCLUDE('ABWINDOW.INC')

 

MAP

 MODULE('VIEWE002.CLW')

BrowseFiles  PROCEDURE

 END

END

 

BrowseFiles  PROCEDURE

 

FilesOpened  BYTE

ViewerActive  BYTE(False)

Filename   STRING(FILE:MaxFilePath),AUTO,STATIC,THREAD

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

RECORD     RECORD,PRE()

Line       STRING(255)

       END

      END

ViewWindow  WINDOW('View an ASCII File'),AT(3,7,296,136),SYSTEM,GRAY

       LIST,AT(5,5,285,110),USE(?AsciiBox),IMM,FROM('')

       BUTTON('&Print...'),AT(7,119),USE(?Print)

       BUTTON('&Search...'),AT(44,119),USE(?Search)

      END

ThisWindow  CLASS(WindowManager)

Init      PROCEDURE(),BYTE,PROC,VIRTUAL

TakeAccepted  PROCEDURE(),BYTE,PROC,VIRTUAL

      END

 

Viewer    AsciiViewerClass            !declare Viewer object

Searcher  AsciiSearchClass            !declare Searcher object

Printer   AsciiPrintClass             !declare Printer object

 

CODE

GlobalResponse = ThisWindow.Run()

 

ThisWindow.Init PROCEDURE()

ReturnValue   BYTE,AUTO

CODE

ReturnValue = PARENT.Init()

IF ReturnValue THEN RETURN ReturnValue.

SELF.FirstField = ?AsciiBox

SELF.VCRRequest &= VCRRequest

SELF.Errors &= GlobalErrors

OPEN(ViewWindow)

SELF.Opened=True

CLEAR(Filename)

ViewerActive=Viewer.Init(AsciiFile,A1:Line,Filename,?AsciiBox,GlobalErrors)

IF ~ViewerActive THEN RETURN Level:Fatal.

Viewer.AddItem(Searcher)               !register Searcher with Viewer

Viewer.AddItem(Printer)                !register Printer with Viewer

SELF.SetAlerts()

RETURN ReturnValue

 

ThisWindow.TakeAccepted PROCEDURE()

ReturnValue          BYTE,AUTO

 CODE

 ReturnValue = PARENT.TakeAccepted()

 CASE ACCEPTED()

 OF ?Print

  ThisWindow.Update

  IF ViewerActive THEN Viewer.Printer.Ask.  !display Print Options dialog

 OF ?Search

  ThisWindow.Update

  IF ViewerActive

   IF CHOICE(?AsciiBox)>0             !search from current line

    Viewer.Searcher.Ask(Viewer.TopLine+CHOICE(?AsciiBox)-1)

   ELSE

    Viewer.Searcher.Ask(1)            !search from line 1

   END

  END

   END

   RETURN ReturnValue