procedure TfrmYourForm.PrepTheBrowser;
begin
WebBrowser1.Navigate(CURRENTHTML);
WaitDocComplete;
end;
procedure TfrmYourForm.WaitDocComplete;
begin
try
while (not DocComplete) and (not application.terminated) do
Application.ProcessMessages;
if not Application.Terminated then
begin
// Do Stuff like:
// set interfaces
// set doc & frame index variables
end;
except
on E:Exception do
begin
raise Exception.Create( #13#10 + 'ERROR: Unexpected Exception in ' +
'frmYourForm.WaitDocComplete; ' +
#13#10 + E.Message);
end; {on exception}
end; {try}
end;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser1: TWebBrowser;
procedure Button1Click(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
FLoading: Boolean;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.experts-exchange.com');
Floading := True;
while FLoading do Application.ProcessMessages;
ShowMessage('Finished');
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
CurWebrowser: IWebBrowser;
TopWebBrowser: IWebBrowser;
begin
CurWebrowser := pDisp as IWebBrowser;
TopWebBrowser := (Sender as TWebBrowser).DefaultInterface;
FLoading := not (CurWebrowser = TopWebBrowser);
end;
end.
procedure TfrmYourForm.WebBrowser1DocumentComplete( Sender : TObject;
const pDisp : IDispatch;
var URL : OleVariant);
(******************************************************************************
** **
** Procedure: WebBrowser1DocumentComplete **
** **
** Purpose: This procedure **
** **
** Parameters: Sender - TObject - the calling object **
** **
** Exceptions: If an error occurs during this routine's check for the **
** OnDocumentComplete event passing the same Dispatch **
** interface as the OnNavigateComplete event handler, **
** then an exception is raised. **
** **
** Author: Ralph D. Wilson II **
** **
** Date Created: 2005-03-01 **
** **
** Revision History **
** Date Initials Modification **
** 03/01/2005 RDWII Initial code created. ** **
******************************************************************************)
begin
try
{ Only the final OnDocumentComplete event passes the same
Dispatch interface as the OnNavigateComplete event handler.}
if (pDisp = CurDispatch)
then begin
DocComplete := True;
CurDispatch := nil; {clear the global variable }
end; {if}
except
on E:Exception do
begin
raise Exception.Create( #13#10 + 'ERROR: Unexpected Exception in ' +
'frmYourForm.WebBrowser1DocumentComplete; ' +
#13#10 + E.Message);
end; {on exception}
end; {try}
end;