유돌이

calendar

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

Notice

2008. 12. 24. 17:56 델파이
Author: sTenYa

Category: Internet / LAN

{....}

private
  procedure 
SearchAndHighlightText(aText: string);
    
{....}

uses mshtml;

{ .... }


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;

// Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
  
SearchAndHighlightText('delphi');
end;


'델파이' 카테고리의 다른 글

레지스트리 값 읽고 쓰기  (0) 2008.12.24
웹에 있는 파일 다운로드 받기(UrlDownloadToFile)  (0) 2008.12.24
델파이 자료형~!  (0) 2008.12.24
문자열 관련 함수  (0) 2008.12.24
델파이에서 브라우저 띄우기  (0) 2008.12.24
posted by 유돌이