AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

webbrowser and Find

Ein Thema von mijack · begonnen am 3. Jun 2007 · letzter Beitrag vom 4. Jun 2007
Antwort Antwort
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
marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#2

Re: webbrowser and Find

  Alt 3. Jun 2007, 12:38
Hi,

you only should start to search and highlight after the document is loaded and rendered. You can detect this state when you provide code for the event OnDocumentComplete(). There is absolutely no sense in looping through a list of urls without some means of control for the user.

Regards
  Mit Zitat antworten Zitat
mijack

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

Re: webbrowser and Find

  Alt 3. Jun 2007, 14:11
Thank you marabu

is there any means i cann search these Pages Without loading them into this WebBrowser, or can i load them in Memory and search

many thanks
  Mit Zitat antworten Zitat
marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#4

Re: webbrowser and Find

  Alt 4. Jun 2007, 07:23
Of course, you can fetch the markup without rendering it. Use TIdHTTP.Get() which is employed by UrlDownload() - or have a look at UrlMon.UrlDownloadToFile().
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:45 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz