Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

How to call the Find dialog in WebBrowser

By Zarko Gajic, About.com

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

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TWebBrowser
  6. How to call the Find dialog in WebBrowser

©2009 About.com, a part of The New York Times Company.

All rights reserved.