tondog
asked on
In Delphi, Anyone know how to REALLY REALLY pause the program till the WebBrowser website is really really finished loading.
I have tried several ways to try to detect if the webbrowser is finished loading a website.
I can't seem to find a solution that always works though.
while WebBrowser1.ReadyState <> READYSTATE_COMPLETE do application.ProcessMessage s;
This seems to work the best -- following the NAVIGATE command
But doesnt seem to work when i submit a form.
Anyone know a method to REALLY check if the webbrowser is still busy
p.s. I don't really care about flash or images loading.
thanks!
I can't seem to find a solution that always works though.
while WebBrowser1.ReadyState <> READYSTATE_COMPLETE do application.ProcessMessage
This seems to work the best -- following the NAVIGATE command
But doesnt seem to work when i submit a form.
Anyone know a method to REALLY check if the webbrowser is still busy
p.s. I don't really care about flash or images loading.
thanks!
Short answer? "Yes."
Sorry, couldn't resist that one. ;-)
Okay, here's what I have done with geat success:
Okay, here's what I have done with geat success:
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;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
8080_Diver,
thanks but what is DocComplete ?
thanks but what is DocComplete ?
Hi, you can use something like this:
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.
ASKER
This seemed to work good
though i have no idea why.
thanks!
though i have no idea why.
thanks!
Oops,
Forgot one of the procedures. This one is associated with the DocumentComplete Event.
DocComplete is a boolean that is used to flag the success.
Forgot one of the procedures. This one is associated with the DocumentComplete Event.
DocComplete is a boolean that is used to flag the success.
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;