Apply the IE browser control in the Delphi Program

Source: Internet
Author: User
Document directory
  • 1. Introduce IE browser controls in Delphi
  • 2. Use IE browser controls in the Delphi Program
  • 3. Two examples of Applying IE browser controls in Delphi

 

Apply the IE browser control Wang fa Jun in the Delphi Program

---- You may still remember the example of the browser in the example program of Delphi. In that example, a browser is created using the attributes and methods of the thttp control. This example is used to understand how to use the thttp control. But few people use it as a real browser. The reason is very simple. The function is too limited. It does not support frame, script language, and HTML files. Most users are using IE or navigator. Our programmers are also happy to use a ready-made browser. When a browser is needed, they can call an external browser in the program through methods such as winexec or CreateProcess for users to use. This method is really easy, but it always makes me a little unwilling to give control of the program to other external programs, which makes me very troublesome, especially when the computer usage level of application software users is not very high. If you have a browser control, you can embed the browser into your own program, which should be quite good.

---- If the external environment of your software is Win95 + IE or Win98 (the usage of such software is still very high), then an IE browser control is available in the system, maybe you haven't noticed it for a long time. Don't waste resources. Use it. When ie3.x or ie4.x is installed in the system, the IE browser control has been registered to the system. Run regedit and use the "Search" function under the "edit" menu to find the "shell. explorer, you will find that the IE control has been registered in the system as an ActiveX control, so that we can use this control in Delphi.

1. Introduce IE browser controls in Delphi

 

---- The IE browser controls must provide the display function before they can be used. Therefore, you cannot use createoleobject in the program to obtain an instance and directly use its attributes and Methods. Otherwise, the program may cause errors during running; in this case, you need to use the "Import ActiveX Control" function provided in Delphi. the operation method is described below.

---- In the "components" menu, call the "Import ActiveX Control" function and select "Microsoft Internet controls (version1.1)" in the registered controls (registration control) list )", the following prompt bar shows the path C:/pwin98/system/shdocvw. DLL, which lists three registrable controls in the class names (type list): twebbrowser_v1, twebbrowser, and tshellfolderviewoc, they are the ie3 browser control, the ie4 browser control, and the Microsoft shell folder view router control. Click Install. After the installation is complete, three controls are added to the ActiveX control bar, namely twebbrowser_v1, twebbrowser, and tshellfolderviewoc. In the imports directory of Delphi, a file shdocvw_tlb.pas is created, the packaging details of these three controls, including the properties and methods of the controls, can be used as a reference for using controls.

2. Use IE browser controls in the Delphi Program

 

----

Take twebbrowser (ie 4 browser control) as an example. Common attributes and methods of twebbrowser include: Goback: method, which is used to return to the previous page. Goforward: method. Go to the next page. Gohome: method. Call the default homepage page. This page is set in the options of IE. Gosearch: method. Call the default search page, which is set in the options of IE. Navigate (const URL: widestring; var flags, targetframename, postdata, headers: olevariant): method, call the specified page. The specific parameter is as follows: URL: Specify the URL of the page. Flags: Word type. The function is unclear. It can be set to 0. Targetframename: widestring: the frame in which the page is opened. If it is an empty string, it is opened in the current frame. If the frame specified by targetframename exists, it is opened in the frame; if the frame specified by targetframename does not exist, a new window is created to open it. This is equivalent to calling an external IE browser. Postdata: Boolean, whether data can be sent. Headers: widestring, the header data of the URL request to be sent. Refresh: Method to refresh the current page. Stop: method. Stop calling or open the current page. Locationname: attribute (widestring), name of the current location. Locationurl: the URL of the current location of the property (widestring. Busy: attribute (Boolean), whether it is busy. Visible: attribute (Boolean), whether the browser window is visible. (The following attributes are added in twebbrowser, but not in twebbrowser_v1. Their functions are to be explored.) statusbar: attribute (Boolean), whether to display the status bar. Statustext: attribute (widestring), status bar content. Toolbar: Property (sysint), content in the toolbar. Menubar: attribute (Boolean), whether to display menu bar. Fullscreen: attribute (Boolean), whether to display in full screen. Offline: attribute (Boolean), whether to browse offline. Addressbar: attribute (Boolean), whether to display the address bar. Common twebbrowser events include onstatustextchange = procedure (Sender: tobject; const text: widestring) of object;

 

---- When the status bar prompts a change in information, the text parameter indicates the current status bar prompt information. We can update our own status bar prompt information or process other transactions based on this information.

---- Onprogresschange = procedure (Sender: tobject; progress, progressmax: integer) of object;

---- When the progress of the page is changed, the parameter progress is the current progress, and progressmax is the total progress. We can update our own status bar prompts or process other transactions based on these two parameters.

---- Oncommandstatechange = procedure (Sender: tobject; command: integer; Enable: wordbool) of object;

---- When a new command is executed, the command is the command identifier, and enable indicates whether to allow the command to be executed. ontitlechange = procedure (Sender: tobject; const text: widestring) of object;

---- When the page title changes, text is the current title.

---- Onpropertychange = procedure (Sender: tobject; const property _: widestring) of object;

---- When the page property changes, property _ is the property name ondownloadcomplete: tpolicyevent

---- Occurs after the download page is complete.

---- Ondownloadbegin: tpolicyevent

---- Occurs before the download page starts.

3. Two examples of Applying IE browser controls in Delphi

 

---- (1) Create your own help system

---- We use the IE browser control to create a help system for users. The help file consists of multiple HTML files. A Topic corresponds to an HTML file (topic. htm). Each project under a topic corresponds to a tag (# item) in the HTML file ). In this way, we do not have to call IE or winhelp to help users in our system. I believe you know the advantages of HTML Help files over traditional HLP help files.

---- The following example shows how to use the navigate method of the twebbrowser (ie 4 browser control. Note the annotations in the program. (The following is the main snippet of the program ).

{Call the Help file according to the topic and project} procedure showHelp (helptopic, helpitem: string); var targetframename, postdata, heads, flags: olevariant; Url: widestring; begin targetframename: = ''; {specify the frame's Null String, open the Help file in the current frame} postdata: = false; {do not send data} heads: = ''; {header information is Blank} flags: = 0; {flags is set to 0} URL: = helptopic + '. htm # '+ helpitem; {help information URL} with formhelp. webbrowser do {display help information in the IE browser control in the Help Window} begin navigate (URL, flags, targetframename, postdata, heads); {display help information} end;

 

---- (2) display a GIF Animation

---- If you do not have a suitable animation display control, try the following method.

Procedure showgif (giffilename: string); var targetframename, postdata, heads, flags: olevariant; Url: widestring; begin targetframename: = ''; {when an empty string of the frame is specified, open the animation file} postdata: = false; {do not send data} heads: = ''; {header information is Blank} flags: = 0; {flags is set to 0} URL: = giffilename; with formgif. webbrowser do {display animations in the IE browser control in the specified window} begin navigate (URL, flags, targetframename, postdata, heads); {display animation file} end;

 

---- The above program is successfully debugged under pwin98 + Delphi3.0.

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.