Save a Web page as a single file (MHT format) using Delphi code

Source: Internet
Author: User

Here's how to save a Web page as a single file (MHT format) using Delphi code:

Uses cdo_tlb, adodb_tlb;
...
PRocedure wb_saveas_mht (Wb:twebbrowser; Filename:tfilename);
Var
Msg:imessage;
Conf:iconfiguration;
Stream: _stream;
url:widestring;
Begin
If not Assigned (WB. Document) then Exit;
URL: = WB. Locationurl;

MSG: = comessage.create;
Conf: = coconfiguration.create;
Try
Msg.configuration: = Conf;
Msg.createmhtmlbody (URL, Cdosuppressall, ",");
Stream: = Msg.getstream;
Stream.savetofile (FileName, adsavecreateoverwrite);
Finally
MSG: = nil;
Conf: = nil;
Stream: = nil;
End
End (* wb_saveas_mht *)


Sample usage:

First Navigate
WebBrowser1.Navigate (' http://delphi.about.com ');

Then save
WB_SAVEAS_MHT (WebBrowser1, ' c:\WebBrowser1.mht ');


Note 1:the _stream class is defined in Adodb_tlb unit so you probably already has 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 a 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 "Cre Ate unit "button.


Data reference: http://www.knowsky.com/336151.html

Save a Web page as a single file (MHT format) using Delphi code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.