Methods


function FindFirst(
   const AText: WideString;
   const AStartPos: Int64;
   AEncoding: TATEncoding;
   AOptions: TATStreamSearchOptions): Boolean;

Starts the search.
Before the search, the FileName or Stream property must be assigned.
Parameters:

  • AText: string to find.
    Unicode string must be in the Little-Endian format.
  • AStartPos: search start position (0-based).
    If it is 0, search will be performed from the beginning or end of the file/stream, depending of "Backward Search" option presence.
  • AEncoding: text encoding. Possible values are:
    • vEncANSI: ANSI encoding (locale dependent)
    • vEncOEM: OEM encoding (locale dependent)
    • vEncEBCDIC: IBM EBCDIC US encoding
    • vEncKOI8: KOI8-R encoding
    • vEncISO: ISO encoding (locale dependent)
    • vEncMac: Macintosh encoding (locale dependent)
    • plus many others, see the complete list in ATxCodepages.pas
  • AOptions: search options that are set of flags:
    • asoCaseSens: Case Sensitive search
    • asoWholeWords: Whole Words search
    • asoBackward: Backward search (Note: ignored in RegEx mode)
    • asoRegEx: RegEx search
    • asoRegExMLine: RegEx multiline search (used with asoRegEx)
Result is True if search was successfull.
In this case you can read the FoundStart and FoundLength properties to get the resulting position and length.
Notes:
  • RegEx notes:
    • On invalid regex this method raises an exception with descriptive message.
    • It is not recommended to use "Case Sensitive" and "Whole Words" options with quite complex regex that already specifies these options. For example, you shouldn't use the "Case Sensitive" option with regex containing (?i), and shouldn't use the "Whole Words" option with regex containing /b or /pZ. Otherwise the search result can be incorrect.
  • Encodings notes:
    • ANSI, OEM, EBCDIC, KOI8, ISO, Mac encodings are always available.
    • EBCDIC, KOI8, ISO, Mac encodings are used via MultiByteToWideChar API, if possible. But if they are not installed on OS (for example, on Win9x), then the hardcoded codepages are used.
    • All other encodings are used via MultiByteToWideChar API, they are available only when installed on OS.
function FindNext(AFindPrevious: Boolean = False): Boolean;

Continues the search.
AFindPrevious: continue search in reverse direction (Note: not supported for RegEx search).
Result is the same as for FindFirst method.