procedure TForm1.SearchWordInRichEdit(const SearchWord: string;
RichEdit: TRichEdit; var FoundWords: TArray<string>);
var
SearchPos: Integer;
WordCount: Integer;
begin
SetLength(FoundWords, 0);
SearchPos := 1;
WordCount := 0;
while SearchPos <= Length(RichEdit.Text) do
begin
SearchPos := Pos(SearchWord, RichEdit.Text, SearchPos);
if SearchPos > 0 then
begin
SetLength(FoundWords, WordCount + 1);
FoundWords[WordCount] := SearchWord;
Inc(WordCount);
SearchPos := SearchPos + Length(SearchWord);
end
else
Break;
end;
end;