Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.

ID: 23992, Load HTML text into TWebBrowser control

by Peter Laman Email: Anonymous

Best way to load HTML text into the WebBrowser control, avoiding problems involved with other techniques.
Download Details
FTP  download also available
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 6.0  to 9.0 1454 downloads
Copyright: No significant restrictions

Size: 1,909 bytes
Updated on Wed, 24 May 2006 02:59:45 GMT
Originally uploaded on Wed, 24 May 2006 02:59:04 GMT
SHA1 Hash: 056D88B08D3CC05EBCC443DE4E4FEA2768C9B82B
MD5 Hash: 93EFC568CB9B05352DFDFC4C427F73DB

    Explore the files in this upload

How to load HTML text directly into the WebBrowser control without first having to save it somewhere?

According to MSDN documentation, one should navigate to "about:blank", to ensure the Document property of the browser is not nil and then obtain a reference to the IPersistStream interface for the Document property. Then the Init method should be called to initialize the document and the Load method should be called to stream in the HTML text. However, this procedure fails on some large, complex HTML text, such as HTML formatted text as created by Excel for data with a more than trivial complexity, or a similar Word document. In those cases, the WebBrowser shows the HTML source text in stead. It seems that the browser doesn't properly recognize the text as HTML and treats it as plain text.

An alternative is to navigate to "about:blank" and then use the IHTMLDocument2.Write method to copy the HTML text. To do this property, one should wait until the document has loaded, so the IHTMLDocument2.Write method is best called from the DocumentComplete event of the browser. It turns out that this procedure does not have the problem as mentioned above. Nicely, it's also easier to program!!

See the self-documenting uStuffHTML.pas for a working example. Call the StuffHTML procedure to write HTML directly into the browser.

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC04