You can use WebBrowser to download, but do not know how to save to file. The real source code access WebBrowser, returns the original format code, the. uses ActiveX; function WB_SaveHTMLCode(WebBrowser: TWebBrowser; const FileName: TFileName): Boolean; var ps: IPersistStreamInit; fs: TFileStream;. uses UrlMon; function DownloadFile(SourceFile, DestFile: string): Boolean; begin try. Result:= UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0.

Author: Tarisar Yozshujora
Country: Saudi Arabia
Language: English (Spanish)
Genre: Video
Published (Last): 4 August 2010
Pages: 171
PDF File Size: 3.68 Mb
ePub File Size: 17.33 Mb
ISBN: 482-3-16190-703-9
Downloads: 38010
Price: Free* [*Free Regsitration Required]
Uploader: Gorg

The simplest of these is the NagivateToLocalFile method. It interacts with the browser control to save the whole document to a stream. See the source files for full details.

GetString Bytes ; dflphi MS. Requirements Implementation Stage 1: How to load and save documents in TWebBrowser in a Delphi-like way. GetBytes S ; Preamble: TBytes ; begin MS: We simply check the start of the URL string for some known local protocols etc.

It would be a simple matter to adapt the method by adding a default parameter to let the user of the code specify what if any caching should take place this is left as an exercise. The decision is based on whether the document is stored locally or is on the internet. It works, but not solve the problem The constructor is very simple — it just stores a reference to the TWebBrowser control that the object is wrapping.

Es ist dir nicht erlaubtneue Themen zu verfassen. TEncoding ; var Bytes: Sign up using Facebook. We then check to see if the document supports the IPersistStreamInit interface, getting a reference to the supporting object.


Original XML from the webserver: The code I’ll present here is for illustration purposes only. We create the needed TStreamAdapter object by passing a reference to our stream in its constructor. SaveToStream ms ; ms.

If you add anything really useful, please let me know.

Save to Web Archive (.mht) file

And this is where it gets more complicated — for the first time we have to mess around with the COM stuff. DataString ; finally StringStream. We will also need to re-implement the original LoadFromString method.

If Encoding is the same as the document’s encoding then calling this method is wasteful. View Source for WebBrowser control from C program Only the final solution the poster adds to the group as an attachment I can not find.

How to save the page displayed in a TWebBrowser to a single page .mht web archive file

TStringStream ; begin StringStream: Stack Overflow works best with JavaScript enabled. The Unicode version of the method writes the browser’s document into a temporary memory stream. GetTickCount ; repeat Application. We first record the default encoding to return if we can’t examine the document for any reason. When we discussed requirements we decided we needed to be able to specify an encoding when writing to files and streams and when reading from a string. Xave the new code:.

This is done because we need to interpret the output stream according to its encoding. By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.


The stream is prefixed by any byte order mark required by the encoding. The second requirement was to provide access to the encoding used for the browser control’s current document. We then save the string to the stream using the encoding provided in the Encoding parameter, prefixed by any required byte order mark.

Create Stream ; PersistStreamInit. The approach we will twehbrowser is to develop a wrapper class for TWebBrowser rather than derive a new class from it. As mjn pointed out, the values of password type inputs will not be shown. Several people’s ideas and code samples have been used in developing this code.

A demo program that can be used to test and exercise the code presented here is available for download. A boolean value indicating whether the file exists is returned.

It’s all so very COM! The local Pause procedure does a busy wait, polling the message queue for about 5ms at a time. Whosrdaddy – Thank You! You can also do this with TWebBrowserbut its not straightforward — not very “Delphi” — you have to query and manipulate interfaces and all sorts of tewbbrowser. TObject twebbgowser procedure Button1Click Sender: TEncoding ; var FileStream: So we call GetStreamEncoding to find the encoding used to generate the stream.