Cry about...
Delphi Programming with TWebBrowser
How to PUT custom HTML into a TWebBrowser
The following function shows how to take a string containing HTML and get an instance of TWebBrowser to display that HTML:
procedure LoadHtmlIntoBrowser(browser: TWebBrowser; const html: String);
var
memStream: TMemoryStream;
begin
//-------------------
// Load a blank page.
//-------------------
browser.Navigate('about:blank');
while browser.ReadyState <> READYSTATE_COMPLETE do
begin
Sleep(5);
Application.ProcessMessages;
end;
//---------------
// Load the html.
//---------------
memStream := TMemoryStream.Create;
memStream.Write(Pointer(html)^,Length(html));
memStream.Seek(0,0);
(browser.Document as IPersistStreamInit).Load(
TStreamAdapter.Create(memStream));
memStream.Free;
end;
and this is an example of it in use, showing how to call it to load some HTML into a browser:
LoadHtmlIntoBrowser(myForm.myBrowser, '<html><head></head><body>Test</body></html>');
These notes are believed to be correct for Delphi 6 and Delphi 7, but may apply to other versions as well.
About the author: Brian Cryer is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.