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: Ketilar Yokora
Country: Armenia
Language: English (Spanish)
Genre: Photos
Published (Last): 3 June 2007
Pages: 389
PDF File Size: 10.7 Mb
ePub File Size: 19.76 Mb
ISBN: 189-8-76517-931-8
Downloads: 63399
Price: Free* [*Free Regsitration Required]
Uploader: Kesho

ProcessMessages ; until Int64 Windows. This is left as an exercise hint: They complement the three LoadXXX methods as follows:. Here is the new implementation of SaveToString. Boolean ; procedure NavigateToResource const Module: TEncoding ; var Doc: Including sensitive data such as passwords.

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

This routine simply copies the provided stream into a TBytes array then uses the GetBufferEncoding class method of TEncoding to determine the encoding. Once we have the stream we simply call the existing LoadFromStream method to load the stream into the document.

Note that, like in InternalLoadDocumentFromStreamwe again try to get the web browser document’s IPersistStreamInit interface and then use its Save method to write the document to the stream. Create Stream ; PersistStreamInit.

The first thing to notice is the WebBrowser property that enables access to the wrapped control. It is not designed for use in its current form in drlphi applications. Load, and we’re done.

TStream ; public constructor Create const WebBrowser: We will also need to re-implement the original LoadFromString method. TStreamAdapter from Delphi’s Classes unit comes to the rescue here — this object implements IStream and translates IStream ‘s method calls into equivalent calls onto the TStream object that it wraps. When we discussed requirements we decided we needed to be able to specify an encoding when writing to files and streams twebbgowser when reading from dlphi string.


Document then begin sl: For much of this we’re going to rely on the encoding support built into Delphi and later, so get ready for some conditionally defined code. If you think I’ve sae anything major, please feel free to add it to the code.

Save to Web Archive (.mht) file

We will re-use these functions later. Hello, Thanks, but it doesn’t work. The implementation of these functions is described in article The resulting stream is then examined by Mauricio Julio’s GetStreamEncoding function to get the encoding. The new, Unicode only, overloaded method first writes the the string to a temporary memory stream, encoded according to the Encoding parameter.

Let’s first look at the stream and string methods, which are very similar:. We do this by navigating to the special about: GetString Bytes ; finally MS. There are three methods that are used to save a document’s code. The code is open source.

As mjn pointed out, the values of password type inputs will not be shown. TMemo; procedure FormCreate Sender: We first record the default encoding to return if we can’t examine the document for any reason. Now let us review the specialised navigation methods.

: get/save the HTML Code from a TWebbrowser?

The constructor is very simple — it just stores a reference to the TWebBrowser control that the object is wrapping.


IPersistStreamInit is used to effectively “clear” the document object using the interface’s InitNew method. Choosing Unicode or UTF-8 examples when loading strings into the demo will fail when it is built with compilers earlier than Delphi Please feel free to take the core unit from the demo and modify, specialise or generalise it for your own purposes. Hello, For saving the internetpage loaded in twebbbrowser TWebbrowser-component are two properties.

You can also do this with TWebBrowserbut its not straightforward — not very “Delphi” — you have to query and manipulate interfaces and all sorts of stuff.

How do I save the contents of TWebBrowser, including user-entered form values? The code was developed using Delphi 7 Professional non-Unicode and Delphi Unicode and tested with both those compilers and Delphi Two overloaded methods are provided.

Note that even though the stream adapter class is freed, the underlying TStream object continues to exist, which is what we want. This control reference is passed as a parameter to the constructor:. TStream ; var PersistStreamInit: The first method accepts the handle of a twebbrowsre module pass HInstance to access the current program.

The first thing to note is that, on non-Unicode compilers, the original version of LoadFromString is unchanged. GetBytes S ; Preamble: