This application is a source code file describing the use of WebBrowser Internet Explorer with a Delphi. Delphi Programming Language will be very useful in learning. It will also give you an idea of how to navigate through your program with WebBrowser Internet Explorer in Delphi.
The TWebBrowser component (in the Delphi IDE's Internet palette) is a Microsoft ActiveX ® control that you can use in the forms of your application to browse Web sites, view Web pages and other documents, and download data that is available on the Internet.
The TWebBrowser component is useful when you don't want to interrupt your workflow by switching from your application to a Web browser or another document viewing application.
The TWebBrowser component can display any Web page that Microsoft Internet Explorer version 3.0 or later (ie 4.0, 4.01, 5, 5.5, 6 ...) can display.
For example, the TTWebBrowser component can display pages that contain the following features:
1. Standard HTML and HTML enhancements such as floating frames and Cascading Style Template
2. Other ActiveX controls
3. Most Netscape add-ons
4. Microsoft Visual Basic Scripting Edition (VBScript) or JavaScript
5. JavaTM applications
6. Multimedia content such as video and audio playback
7. Three-dimensional virtual worlds created with Virtual Reality Modeling Language (VRML)
In addition to opening web pages, the TWebBrowser component can open any ActiveX document that contains most Microsoft Office documents. For example, if Microsoft Office is installed on a user's computer, an application that uses the TWebBrowser component can open and edit Microsoft Excel spreadsheets, Microsoft Word documents, and Microsoft PowerPoint presentations from within the control.
Similarly, if Microsoft Excel Viewer, Microsoft Word Viewer, or Microsoft PowerPoint Viewer is installed, users can view these documents in the TWebBrowser component. With the TWebBrowser component, users of your application can browse sites on the World Wide Web, as well as folders on a local hard disk and local area network.
Users can track hyperlinks by clicking or typing a URL in a text box. In addition, the TWebBrowser component maintains a history list that users can browse to view previously scanned sites, folders, and documents.
View a Web page or document in TWebBrowser
To view a Web page or document in the TWebBrowser component, we must use the Navigate method programmatically. The codes for the navigation method are:
The overview of our application will be as follows:
The URL specifies the path name of a file or the Uniform Resource Locator (URL) of an Internet resource that the Web browser should display. If the URL points to an Internet protocol and a location on an intranet server, the computer running your application must be connected to the Internet or intranet, and must have permission to access that server. If the URL points to a standard file system path on a local hard drive or intranet, the TWebBrowser component opens and displays the document immediately. The TWebBrowser component can open Microsoft Office documents, text files, and HTML documents.
Flags - A set of values that specify whether the resource should be added to the history list, read from the cache, and whether the resource is displayed in a new window.
TargetFrameName is zero if the name of the frame to show the source or if the source should not be displayed in a named frame.
PostData contains data sent to the server when using Navigate to generate an HTTP POST message. If PostData is zero, Navigate generates an HTTP GET message. If the URL does not specify an HTTP URL, PostData is ignored.
Headers contain headers sent to servers when the URL represents an HTTP URL. HTTP headers, the desired action of the server, data type, and so on.
Now let's conclude.
Create a new VCL Application project and save it to a folder. Then, add a TWebBroswer component to the form. Then add buttons, edits, or other necessary components to create them as follows.
Here are our codes:
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.OleCtrls, SHDocVw, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Buttons; type TForm1 = class(TForm) WebBrowser1: TWebBrowser; Panel1: TPanel; Label1: TLabel; editURL: TEdit; btnLoad: TButton; btnnext: TSpeedButton; btnback: TSpeedButton; btnrefresh: TSpeedButton; btnHome: TSpeedButton; btnStop: TSpeedButton; btnQuit: TSpeedButton; procedure btnLoadClick(Sender: TObject); procedure editURLKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure btnbackClick(Sender: TObject); procedure btnnextClick(Sender: TObject); procedure btnHomeClick(Sender: TObject); procedure btnrefreshClick(Sender: TObject); procedure btnStopClick(Sender: TObject); procedure btnQuitClick(Sender: TObject); procedure WebBrowser1TitleChange(ASender: TObject; const Text: WideString); private { Private declarations } procedure OpenURL; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.OpenURL; begin WebBrowser1.Navigate(editURL.Text); // URL can be www.google.com // URL can be C:\testfolder // URL can be C:\testfolder\tset1.jpg end; procedure TForm1.btnLoadClick(Sender: TObject); begin OpenURL; end; procedure TForm1.editURLKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_RETURN then OpenURL; end; procedure TForm1.btnbackClick(Sender: TObject); begin WebBrowser1.GoBack end; procedure TForm1.btnHomeClick(Sender: TObject); begin WebBrowser1.GoHome; end; procedure TForm1.btnnextClick(Sender: TObject); begin WebBrowser1.GoForward; end; procedure TForm1.btnQuitClick(Sender: TObject); begin WebBrowser1.Quit; end; procedure TForm1.btnrefreshClick(Sender: TObject); begin WebBrowser1.Refresh; end; procedure TForm1.btnStopClick(Sender: TObject); begin WebBrowser1.Stop; end; procedure TForm1.WebBrowser1TitleChange(ASender: TObject; const Text: WideString); begin editURL.Text := Text; end; end.
No reviews found.
No comments found for this product. Be the first to comment!