Author: Tomas Rutkauskas
Using the TWebBrowser component (Delphi 5), I am looking for a way to store the
HTML code of the TWebBrowser. When I use the right mouse button, I can store the
HTML code, but I would like to do this programmatically.
Answer:
1 uses2 ActiveX;
3 4 {Saves the HTML document - referenced through 'Document' - to a stream}5 6 procedure SaveDocumentSourceToStream(Document: IDispatch; Stream: TStream);
7 var8 PersistStreamInit: IPersistStreamInit;
9 StreamAdapter: IStream;
10 begin11 {Delete content of stream}12 Stream.Size := 0;
13 Stream.Position := 0;
14 {IPersistStreamInit - get document interface}15 if Document.QueryInterface(IPersistStreamInit, PersistStreamInit) = S_OK then16 begin17 {Use StreamAdapter to get the IStream interface for our stream}18 StreamAdapter := TStreamAdapter.Create(Stream, soReference);
19 {Save data from document into stream}20 PersistStreamInit.Save(StreamAdapter, False);
21 {Destroy StreamAdapter. Optional.}22 StreamAdapter := nil;
23 end;
24 end;