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: Tetaxe Maubei
Country: Mozambique
Language: English (Spanish)
Genre: Literature
Published (Last): 15 October 2010
Pages: 423
PDF File Size: 20.95 Mb
ePub File Size: 9.41 Mb
ISBN: 791-7-15125-703-1
Downloads: 92566
Price: Free* [*Free Regsitration Required]
Uploader: Kazirg

How can you simulate this option and save it to twebrbowser If you use the “view source” option in the browser the XML -file will open OK without any formatting by the browser.

TObject ; procedure Button1Click Sender: As noted above, the code presented in this article does not work correctly when loading and saving in Unicode or UTF-8 when built twebrbowser a non-Unicode version of Delphi. As can be seen this is all quite straightforward if you’re used to using TStream s. Two overloaded methods are provided. IPersistStreamInit is used to effectively “clear” the document object using the interface’s InitNew method. And this is where it gets more complicated — for the first time we have to mess around with the COM stuff.

How to load and save documents in Dave in a Delphi-like way. IStream ; begin if not Assigned WebBrowser. This first stage won’t worry about Unicode support other than that needed to make the code compile and work with Delphi and later. There are three methods that are used to save a document’s code. Hello, On the web I’ve searched and searched, but my question seems a difficult problem.

You can thank me by accepting this answer ; meta. The constructor is very simple — it just stores a reference to the TWebBrowser control that the object is wrapping. The second requirement was to provide access savee the encoding used for the browser control’s current document. Various useful articles can also be found on the Microsoft Developer Network.


Sure this is possible! Sign up using Email and Password. You should call the SaveToStream overload that does not take an Encoding parameter instead. Free; end; finally sl. With the real source of the page, but it’s an execute of a notepad session and I’m not able to save it in the delphi code Sign up or log in Sign up using Google.

If you add anything really useful, please let me know. A demo program that can be used to test and exercise the code presented here is available for download. Don’t expect it to be perfect for production code, although you should be able to use it as a basis.

It creates a stream onto the file then passes the stream and the encoding to the overloaded version of SaveToStream. Firstly we decide whether to use the browser’s cache to access the document. Original XML from the webserver: The sve are some unknown characters. twebgrowser

Save to Web Archive (.mht) file

The overloaded methods vary in the way the module is described. TBytes ; begin MS: Twebbrowsdr we have a reference to the safe document in Doc we create a memory stream object and save the browser content into it by calling InternalSaveDocumentToStream. The code I’ll present here is sqve illustration purposes only. This method simply checks if the file exists and, if so, prefixes the given file name with the file: If you’re wandering why we don’t free StreamAdapter and PersistStreamInit it’s because they are both interfaced objects and will be automatically destroyed at the end of the method by Delphi’s built in interface reference counting.


TEncoding ; var FileStream: The second method is simply passed a module name as a string. Boolean ; procedure NavigateToResource const Module: TObject ; var Html: The implementation of these functions is described in article The approach we will take is to develop a wrapper class for TWebBrowser rather than derive a new class from it.

Trackbacks are an Pingbacks are an Refbacks are aus Foren-Regeln. For much of this we’re going dlphi rely on the encoding support built into Delphi and later, so get ready for some conditionally defined code.

How to save the contents of the Twebbrowser to a file?

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.

StringToStreamBOMdescribed twebborwser, first converts the string into a byte array according the required encoding. The simplest of these is the NagivateToLocalFile method. GetTickCount ; repeat Application.

However, the character set can also be specified in HTML code. We simply check the start of the URL string for some known local protocols etc.

: get/save the HTML Code from a TWebbrowser?

Once we have the stream we simply call the existing LoadFromStream method to load the stream into the document. The public methods fall naturally into several groups and, rather than explaining the purpose of each method now, we will look at them in groups.

We will re-use these functions later. See twebbbrowser source files for full details. The first thing to note is that, on non-Unicode compilers, the original version of LoadFromString is unchanged.