Copyright: Visual Help Copyright® 1993 Firas Bushnaq


CONTENTS
FindText Component

Properties

Methods

Description

The find text component provides a means to easily search any file for a text string.

Using the Tfindtext component

 Supply the filename and text string to search for, call the searchfile method and then query the filepos property.  Refer to the discussion of properties for more detail.

Example:

findtext1.filename := 'c:\delphi\readme.txt';
findtext1.findstring := 'delphi';
findtext1.casesensitive := false;
findtext1.searchfile;
If findtext1.filepos > 0 then
  ShowMessage('Found at: ' + inttostr(findtext1.filepos);


Properties

Filename

FindString

Casesensitive

FilePos

Found


Filename Property

Description

The filename property indicates which file to search for the given text string.

Example:

findtext1.filename := 'c:\delphi\readme.txt';
findtext1.findstring := 'delphi';
findtext1.casesensitive := true;
findtext1.searchfile;

The above example performs a casesensitive search of the file 'c:\delphi\readme.txt' for the string 'delphi';


Findstring Property

Description

The findstring property indicates the text string to search for in the given file.

Example:

findtext1.filename := 'c:\delphi\readme.txt';
findtext1.findstring := 'delphi';
findtext1.casesensitive := true;
findtext1.searchfile;

The above example performs a casesensitive search of the file 'c:\delphi\readme.txt' for the string 'delphi';


Casesensitive Property

Description

The casesensitive property indicates whether the search should be case sensitive or not.  The default value is false.

Example:

findtext1.filename := 'c:\delphi\readme.txt';
findtext1.findstring := 'delphi';
findtext1.casesensitive := true;
findtext1.searchfile;

The above example performs a casesensitive search of the file 'c:\delphi\readme.txt' for the string 'delphi';


Filepos Property

Description

The filepos property indicates the position within the file where the given text string was found.  The data type is longint and the value is set to zero if the string was not found.

Example:

findtext1.filename := 'c:\delphi\readme.txt';
findtext1.findstring := 'delphi';
findtext1.casesensitive := true;
findtext1.searchfile;
if findtext1.filepos > 0 then
  ShowMessage('The text was found at position: ' +     inttostr(findtext1.filepos);

The above example performs a casesensitive search of the file 'c:\delphi\readme.txt' for the string 'delphi';


Found Property

Description

Found is a read only boolean property indicating the results of the search.
You can also use the filepos property to determine whether a search was successfull or not.

See Also:

FilePos Property


Methods

Searchfile


Searchfile Method

The searchfile method searches the given file for the indicated text string.  If the text is found, the component sets its filepos property to the position within the file.  If the text was not found then the resulting value of the filepos property is set to zero.

Example:

findtext1.filename := 'c:\delphi\readme.txt';
findtext1.findstring := 'delphi';
findtext1.casesensitive := true;
findtext1.searchfile;

The above example performs a casesensitive search of the file 'c:\delphi\readme.txt' for the string 'delphi';  The position of the first occurrence of the string can be retrieved from the filepos property after the search is performed.