About the author
So, after I retrieved the XML from a feed, I placed the retrieved content into a string after some formatting.
I formatted it as such
<HTML><BODY>XML CONTENT</BODY></HTML>
I placed the formatted string into a string variable. Then, I attempted to load it into the WebBrowser as such.
WebBrowser1.Stop;V := WebBrowser1.Document;V.Open;V.Clear;V.Write(HTML);V.Close;
where V is declared as a variant and HTML is the formatted HTML.
This resulted in a few problems. Sometimes, link in the displayed content will not work. Clicking on some links will work. Clicking on some links will fail. Copying to the clipboard will not work also.
So, I tried another method.
SS := TStringStream.Create(HTML);LoadFromStream(SS);SS.Free;
LoadFromStream is coded so:
var PersistStreamInit: IPersistStreamInit; StreamAdapter: IStream;begin Assert(Assigned(WebBrowser1.Document)); // Get IPersistStreamInit interface on document object if Supports(WebBrowser1.Document, IPersistStreamInit, PersistStreamInit) then begin // Clear document if PersistStreamInit.InitNew = S_OK then begin // Get IStream interface on stream StreamAdapter := TStreamAdapter.Create(Stream); // Load data from Stream into WebBrowser PersistStreamInit.Load(StreamAdapter); end; end;end;
The above code make use of the fact that TWebBrowser is actually implemented by the Internet Explorer control, and uses the IPersistStreamInit interface exposed by it.
However, for this code, another problem arises. Sometimes, certain HTML do not display correctly, even though the HTML is correct!
Eventually, I persisted the HTML to disk, and then loaded the file directly into TWebBrowser using the Navigate method, like so,
WebBrowser1.Navigate(WideString(URL), EmptyParam, EmptyParam, EmptyParam, Headers); while WebBrowser1.ReadyState <> READYSTATE_COMPLETE do begin Application.ProcessMessages; Sleep(0); end;
where URL is the filename of the persisted HTML content. This method solves all the problems that the other methods don't.
Continued discussion of undocumented Delphi 8 Property Access Specifiers, and other ways of adding and removing delegates / events handlers, including clearing the list of all the delegates / event handlers.