2

For example in this code:

procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
begin
        ShowMessage('Download Completed');
end;

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

"WebBrowser1DownloadComplete" message appears several times on 1 Navigate.
This is annoying and makes this event almost useless.

Why is this happening? How to avoid this?
Thankyou

Bruce McGee
  • 15,076
  • 6
  • 55
  • 70
SmRndGuy
  • 1,719
  • 5
  • 30
  • 49
  • 1
    It happens because of frames. Each time this event fires, one frame has been downloaded. Anyway, are you sure you need to watch the `OnDownloadComplete` ? Don't you want to use the `OnDocumentComplete` instead ? For `OnDocumentComplete` you could use [`this advise`](http://stackoverflow.com/a/10105697/960757) but for your case can't tell you more. – TLama Jul 21 '12 at 17:18
  • 1
    So thats why this is happening. thanks – SmRndGuy Jul 21 '12 at 18:25

1 Answers1

2

Perhaps the OnNavigationComplete2 event handler is more suitable for you application.

Occurs immediately after the Web browser successfully navigates to a new location.

Write an OnNavigateComplete2 event handler to take specific action when the Web browser successfully navigates to a new resource. The event can occur before the document is fully downloaded, but when it occurs at least part of the document must be received and a viewer for the document created.

Lawrence Barsanti
  • 31,929
  • 10
  • 46
  • 68
  • OnNavigateComplete2 too behaved like this but meh, I decided to go with it instead of against it. Thanks for the info about it. – SmRndGuy Jul 21 '12 at 18:25
  • Why is this the accepted answer? It neither explains nor solves the problem, which are the two things the question requested. – Rob Kennedy Jul 23 '12 at 03:02
  • Because there is no other answer and the system was constantly annoying me to pick the best answer thus I had to do that. – SmRndGuy Jul 27 '12 at 22:58