4

I am trying to use TWebBrowser in Console/Service type of application (without any windows). Navigate is definitely doing something, but it never calls onDocumentComplete. Is there any other way to get access to IHTMLDocument2 of some URL?

Thank you.

Nipp
  • 103
  • 6
  • 2
    What, specifically, are you hoping to accomplish? TWebBrowser might not be your only option here. – Michael Madsen May 31 '11 at 20:11
  • If you want to download some HTML or whatever through HTTP you are better of with a HTTP Client like one from Indy – Lars Truijens May 31 '11 at 20:15
  • 1
    Do you just want to download something? http://stackoverflow.com/questions/4521535/delphi-file-downloader-component/4521575#4521575 – Andreas Rejbrand May 31 '11 at 20:35
  • @Michael Madsen, I would prefer to have IE for redirects, cookies and so on. Plus, ultimate goal is to extract some text information from the web page. So, access to DOM would be pretty useful here. – Nipp Jun 05 '11 at 17:15
  • @Andreas Rejbrand, I am trying to implement "content watchdog". We have old in-house project that does the task. But it is not precise enough and gives ton of false-positives, when site changes some scripts on the web page. My thanks to everyone who sent the response. I will try Handle Needed method. Thou, it might be an issue if engine is used from non-interactive Service. We'll see. – Nipp Jun 05 '11 at 17:18
  • Serge - did you ever get this to work? I too have the same need. I am trying to create a service to verify if url links exist on certain pages. While Indy works fine for the main page, there could be tons of embedded java script (one of the more common is Disqus) which Indy would miss. I tried the HandleNeeded but this did not work. I also tried making a form too. No luck. – M Schenkel Jun 14 '11 at 18:32

1 Answers1

1

Before using the TWebBrowser instance (e.g. with Navigate2), call its HandleNeeded method. This will allocate an 'invisible' parent window handle and straighten out any event issues.

Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67
  • `HandleNeeed()` does not allocate a hidden parent window. It requires the `Parent` property to be assigned beforehand. The browser is a visual control. It needs a visual parent window. – Remy Lebeau Jun 01 '11 at 06:26
  • It calls TWinControl.CreateHandle, which calls CreateWnd, which creates the needed visual window handle. (though 0x0 pixels big, and not visible, but still visual) – Stijn Sanders Jun 01 '11 at 08:37