程序大致应该是:
procedure TForm1.Button1Click(Sender: TObject);
var
FoundAt: LongInt;
StartPos, ToEnd: Integer;
position:string;
i:integer;
begin
with RichEdit1 do
begin
StartPos := 0;
ToEnd := Length(Text);
FoundAt := FindText(edit1.text, StartPos, ToEnd, [stMatchCase]);
while FoundAt <> -1 do
begin
SelStart := FoundAt;
position:=position+' '+inttostr(foundat);
SelLength := Length(edit1.text);
StartPos := SelStart + SelLength;
ToEnd := Length(Text) - StartPos;
FoundAt := FindText(edit1.text, StartPos, ToEnd, [stMatchCase]);
end;
label2.caption:=position;
end;
end;