Re: Delphi FindDialog with a RichEdit

Posted by webmaster Guido on June 13, 2005

In Reply to: Re: Delphi FindDialog with a RichEdit posted by joe90 on June 12, 2005

: I was just going back over the code here, and I was wondering about a couple of things in these lines:

: sText := Copy(RE.Text, StartFrom, Length(RE.Text) - StartFrom - 1);

: - Why does the Copy() have a -1 on the end?

: PreviousFoundPos := FoundPos + StartFrom - 1;

: - Why does this also have a -1 on the end?

Shame on me, that was a serious typo. Of course it must be +1 instead of -1:
sText := Copy(RE.Text, StartFrom, Length(RE.Text) - StartFrom + 1);

On the other hand, this line was correct:

  PreviousFoundPos := FoundPos + StartFrom - 1; 

Consider searching for "ab" in "abcabcde".
- When the first Find is completed, PreviousFoundPos has become 1
- During the second Find:

  StartFrom := 1 + Length('ab');           // 3 
  sText := Copy('abcabcde', 3, 8 - 3 + 1); // 'cabdce' 
  FoundPos := Pos('ab', 'cabcde');         // 2
  PreviousFoundPos := 2 + 3 - 1;           // 4 

Related Articles and Replies