The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



How to use TGrep


The usage of TGrep is straightforward: first you have to create an instance of TGrep. You can do this either programmatically (see example below) or simply by placing the Grep palette symbol on the form. Then you have to assign the regular expression which is to be used for the search by passing the regular expression to the property RegExp. Thereafter you can apply the regular expression to any string by using the method MatchString. Optionally, the matching algorithm can be set to ignore cases by setting the property IgnoreCase to TRUE.

In addition there are a few diagnostic tools available: the method PrintRegExp prints the list of tokens of scanned regular expressions into a file. Note that PrintRegExp produces valid results only after assigning a regular expression to the property RegExp. The array property RegExpToken provides detailed information of the matching. The number of tokens can be retrieved by the property NrOfRegExpTokens.

Following is the general layout of how to use TGrep.

uses
  stringl;                                      { include stringl }
...
...

var
  MyGrep   : TGrep;
  MyRegExp : string;
  astr     : string;
  ix       : integer;

...
MyGrep := TGrep.Create (nil);       { create an instance of TGrep }
...
MyGrep.RegExp := MyRegExp; { assign the user's regular expression }
...
...                                                { do something }
...       { thereafter 'astr' contains the string to be processed }
...
if MyGrep.MatchString (astr, ix) then
  begin
  ...
  ...                            { now process the matched string }
  ...    { 'ix' contains the start position of the matched string }
  end;
...
MyGrep.Free;                        { remove instance from memory }
...


Last Update: 2013-May-14