Thema: Delphi webbrowser and Find

Einzelnen Beitrag anzeigen

mijack

Registriert seit: 18. Mai 2007
11 Beiträge
 
Delphi 2007 Enterprise
 
#1

webbrowser and Find

  Alt 3. Jun 2007, 12:25
I use this code to find and highlight a word in the WebBrowser :
Delphi-Quellcode:
procedure TForm1.SearchAndHighlightText(aText: string);
var
  tr: IHTMLTxtRange; //TextRange Object
begin
  if not WebBrowser1.Busy then
  begin
    tr := ((WebBrowser1.Document as IHTMLDocument2).body as IHTMLBodyElement).createTextRange;
    //Get a body with IHTMLDocument2 Interface and then a TextRang obj. with IHTMLBodyElement Intf.
 
    while tr.findText(aText, 1, 0) do //while we have result
    begin
      tr.pasteHTML('<span style="background-color: Lime; font-weight: bolder;">' +
        tr.htmlText + '</span>');
      //Set the highlight, now background color will be Lime
      tr.scrollIntoView(True);
      //When IE find a match, we ask to scroll the window... you dont need this...
    end;
  end;
end;
I fill ListBox1 :
Delphi-Quellcode:
Var
i:Integer;
begin
if Opendialog1.execute then
For i:=0 to Opendialog1.files.cout-1 do
Listbox1.items.add(Opendialog1.Files[i]);
end;
So what i want is that the webbrowser navigates all the pages in the ListBox1
what i do :
Delphi-Quellcode:
Var
i:integer;
begin
For i:=0 to listbox1.items.cout-1 do
begin
{Let's suppose listbox1 contains :
Page1
page2
page3
}


WebBrowser1.Navigate(ListBox1.Items.Strings[i]);
SearchAndHighlightText(Edit1.text); // I use edit1 to type the searched keyword
But when i execute it the webbrowser navigates only the :
1st and the Last page.
  Mit Zitat antworten Zitat