1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| function FindTextAll(re: TRichEdit; sText: string; options: TSearchTypes): TIntegerDynArray;
var
iStart, iFound, iLength: integer;
begin
SetLength(Result, 0);
iStart := 0;
iLength := Length(re.Lines.Text);
while iStart < (iLength - Length(sText)) do
begin
iFound := re.FindText(sText, iStart, iLength - iStart, options);
if iFound = -1 then
Exit;
SetLength(Result, Succ(Length(Result)));
Result[High(Result)] := iFound;
iStart := iFound + Length(sText);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
F:textfile;
lig:string;
start: integer;
TextCherche: string;
ida: TIntegerDynArray;
begin
{$I-}
FileMode :=0;
assignfile(F,'cadeaux.txt');
reset(F);
while not eof(F) do begin
readln(F,lig);
edit2.Text:=lig;
Richedit1.Text:=idhttp1.Get('http://www.cool.fr/'+edit2.Text); //Edit2 recupère la ligne dans le fichier texte
TextCherche := Edit3.Text; //mot a Chercher
ida := FindTextAll(RichEdit1, TextCherche, []);
for i := Low(ida) to High(ida) do
with RichEdit1 do
begin
SelStart := ida[i];
SelLength := Length(TextCherche);
RichEdit1.SetFocus;
end;
with TStringList.Create do
begin
label1.Caption :=(IntToStr(Count));
Free;
if RichEdit1.SelStart <> 0 then
label1.Caption :='message trouvé'
else
label1.Caption :='message non trouvé';
end;
closefile(F);
end;
end;
end. |
Partager