LAN Web TCP Delphi

Title: Saving raw HTML source from TWebBrowser to disk
Question: How to save raw HTML source from TWebBrowser.Document to disk.
Answer:
TWebBrowser.Document implements IPersistStreamInit which exposes Save() method. All you need to know is how to use this method along with given object which implements IStream. We could simply use TStreamAdapter for this purpose.
Note that IPersistStreamInit and IStream interfaces are declared inside ActiveX unit.
Here's how to do it.
procedure TForm1.SaveHTMLSourceToFile(const FileName: string;
WB: TWebBrowser);
var
PersistStream: IPersistStreamInit;
FileStream: TFileStream;
Stream: IStream;
SaveResult: HRESULT;
begin
PersistStream := WB.Document as IPersistStreamInit;
FileStream := TFileStream.Create(FileName, fmCreate);
try
Stream := TStreamAdapter.Create(FileStream, soReference) as IStream;
SaveResult := PersistStream.Save(Stream, True);
if FAILED(SaveResult) then
MessageBox(Handle, 'Fail to save HTML source', 'Error', 0);
finally
{ we are passing soReference in TStreamAdapter constructor,
it is our responsibility to destroy the TFileStream object. }
FileStream.Free;
end;
end;
pocedure TForm1.Button1Click(Sender: TObject);
begin
if SaveDialog1.Execute then
SaveHTMLSourceToFile(SaveDialog1.FileName, WebBrowser1);
end;
Please visitIE FAQ site http://members.home.net/hfournier/IE & Delphi site http://www.euromind.com/iedelphi/