首先在uses中加入ActiveX,MSHTML,OleCtrls,SHDocVw,然后编写代码
procedure 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(0,'Fail to Save HTML Source','Error',mb_iconerror);
finally
FileStream.Free;
end;
end;
initialization
OleInitialize(nil);
finalization
OleUninitialize;