1. Computing & Technology

Discuss in my forum

How to call the Find dialog in WebBrowser

By , About.com Guide

Here's how to call a stadard IE find dialog for the TWebBrowser component.

Usage: Simply drop an instance of TWebBrowser component on a form (and a Button) and call the find dialog as:

~~~~~~~~~~~~~~~~~~~~~~~~~
uses ActiveX;

procedure WBFindDialog(AWebBrowser: TWebbrowser) ;
const
  CGID_WebBrowser: TGUID = '{ED016940-BD5B-11cf-BA4E-00C04FD70816}';
  HTMLID_FIND = 1;

var
  CmdTarget : IOleCommandTarget;
  vaIn, vaOut: OleVariant;
  PtrGUID: PGUID;
begin
  New(PtrGUID) ;
  PtrGUID^ := CGID_WebBrowser;
  if AWebBrowser.Document <> nil then
    try
      AWebBrowser.Document.QueryInterface(IOleCommandTarget, CmdTarget) ;
      if CmdTarget <> nil then
        try
          CmdTarget.Exec(PtrGUID, HTMLID_FIND, 0, vaIn, vaOut) ;
        finally
          CmdTarget._Release;
        end;
    except
    end;
  Dispose(PtrGUID) ;
end;

procedure TForm1.FormCreate(Sender: TObject) ;
begin
  WebBrowser1.Navigate('http://www.delphi.about.com') ;
end;

procedure TForm1.Button1Click(Sender: TObject) ;
begin
  WBFindDialog(WebBrowser1) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Enable or disable a control by name
« Rounding control corners

©2012 About.com. All rights reserved.

A part of The New York Times Company.