Here's how to save a web page as a single file (MHT format) using Delphi code:
UsesCdo_tlb, adodb_tlb ;...ProcedureWb_saveas_mht (WB: twebbrowser; filename: tfilename );VaRMSG: iMessage; Conf: iconfiguration; stream: _ stream; Url: widestring;BeginIf NotAssigned (WB. Document)Then Exit; Url: = WB. locationurl; MSG: = comessage. Create; Conf: = coconfiguration. Create;TryMSG. Configuration: = conf; msg. createmhtmlbody (URL, cdosuppressall, '',''); stream: = msg. getstream; stream. savetofile (filename, adsavecreateoverwrite );FinallyMSG: =Nil; Conf: =Nil; Stream: =Nil;End;End;(* Wb_saveas_mht *) |
Sample usage:
// First navigateWebbrowser1.navigate ('HTTP: // delphi.about.com ');// Then saveWb_saveas_mht (webbrowser1, 'c:/webbrowser1.mht '); |
NOTE 1: The _ stream class is defined in adodb_tlb unit that you probably already have created. the iMessage and iconfiguration interfaces code from cdosys. dll library. CDO stands for Collaboration Data Objects-object libraries designed to enable SMTP messaging.
The cdo_tlb is an auto generated unit by Delphi. to create it, from the main menu SELECT "Import Type Library", select "C:/Windows/system32/cdosys. DLL "then click the" Create unit "button.