Apply IE browser control in the Delphi program

zhaozj2021-02-11  231

Apply IE browser control in the Delphi program

Wang Fajun

---- Probably everyone still remembers the example of the browser in Delphi's sample program. In that example, a browser is created using the properties and methods of the control THTTP. This example is used to understand the use of the TTTP control, is really good. But very few people will use it as a real browser, the reason is simple, the function is too limited, does not support Frame, does not support Script scripting language, can not view HTML files in local files, etc.. Most users are using IE or Navigator; our programmer is also happy to use the ready-made browser, when you need to use a browser, call an external browser in the program to use Winexec or createProcess. This approach is really quite quite, but I always make the author a bit unwilling to make the program control to other external programs to make themselves trouble, especially when the application of the application software is not very high. If there is a browser control, you can embed your browser into your own program, it should be quite good.

---- If your software's external environment is Win95 IE or Win98 (such software usage is still very high), there is already an IE browser control in the system, maybe you are long. Time is not found, don't waste resources, take it. When IE3.x or IE4.x has been installed in the system, IE browser controls have been registered in the system. To run the regedit, use the "Find" function under the Edit menu to find the "shell.explorer" key name You will find that IE controls have been registered as ActiveX controls in the system so we can use this control in Delphi.

First, introduce IE browser controls in Delphi

---- Since the IE browser control needs to provide a display function to use, you cannot use createoleObject to obtain an instance with CreateoleObject to use its properties and methods, otherwise the program will cause errors during runtime; then you need to be available in Delphi The "Import ActiveX Control" feature, the operation method is described below.

---- In the "Components" menu, call the "Import ActiveX Control" function, select "Microsoft Internet Controls" in the Registered Controls list, and the pitch is displayed in the prompt bar below. C: /PWIN98/SYSTEM/SHDOCVW.DLL, listed in the class names (Type list): TWEBBBROWSER_V1, TWEBBBBROWSER_V1, TWEBBROWSER and TSHELLFOLDERVIEWOC, IE3 browser control, IE4 browser control, and "Microsoft shell Folder View Router Control. Click Install to install. After the installation is complete, in the "ActiveX" control bar, three controls will be added to TWebBrowser_v1, TWebBrowser and TshellFolderViewoc; in the Imports directory of Delphi, a file shdocvw_tlb.pas will be created, including these three control packaging details Of course, the properties and methods of the control include, it can be used as a reference for us to use controls.

Second, use IE browser control in Delphi program

----

As an example of TWEBBROWSER (IE4 browser control).

The common properties and methods for TWEBBROWSER are mainly:

GOBACK: method, back to the previous page.

GoForward: Method, advance to the next page.

GoHome: Method, call the default home page, which is set in the IE option.

Gosearch: Method, call the default search page,

This page is set in IE's option.

Navigate (Const URL: WideString)

Var flags, targetframename, posterdata,

Headers: olevariant): Method,

Call the specified page, the specific parameters are as follows:

URL: Specifies the URL of the page. Flags:

Word type, the role is still unclear, can be set to 0.

TargetFramename: WideString,

Open the Frame in the page, when the empty string is currently

Open in Frame; TargetFrameName

The specified Frame is turned on the FRAME;

TargetFraMename specified Frame

When there is no existence, create a window open, it is quite

The IE browser that calls the outside.

PostData: Boolean, whether you are allowed to send data.

Headers: WideString,

The header data to be sent by the URL request.

Refresh: method, refresh the current page.

STOP: method, stop calling or open the current page.

LocationName: Name of the current location.

LocationURL: WideString, the URL of the current location.

BUSY: Boolean, is it busy.

Visible: Boolean, whether the browser window is visible.

(The following properties are in TWEBBROWSER,

There is nothing in TWEBBROWSER_V1, and its role is to be explored)

Statusbar: Boolean, whether the status bar is displayed.

StatusText: WideString, status bar content.

Toolbar: The content (sysint), the contents of the toolbar.

MenuBar: Boolean, whether it is displayed in the menu.

Fullscreen: Boolean, is displayed in full screen.

Offline: Boolean, is offline browsing.

AddressBar: Boolean, whether the address bar is displayed.

The common events of TWebBrowser have:

OnStatustextChange = Procedure

(Sender: Tobject; Const text: WideString)

Of Object;

---- When the status bar prompt information, the parameter text is the current status column prompt information, we can update our own status bar to prompt information or handle other transactions based on this information.

---- OnprogressChange = Procedure (Sender: Tobject; Progress, Progressmax: Integer) OF Object;

---- When the progress of the page is turned on, the parameter progress is the current progress. ProgressMax is the total progress, we can update our own status bar prompt information or handle other transactions based on these two parameters.

---- OncommandStateChange = Procedure (Sender: Tobject; Command: Integer; Enable: WordBool) of object;

---- When the new command is executed, Command is the command identifier, and the enable is to allow the command to be executed. Ontitlechange = procedure (sender: Tobject; const text: wideString) of object; ---- When the title of the page changes, Text is the current title.

---- OnpropertyChange = Procedure (sender: TOBJECT; Const property_: WideString) OF Object;

---- When the attribute of the page changes, Property_ is the property name ondownloadcomplete: TNOTIFYEVENT

---- After the download page is completed.

---- ONDOWNLOADBEGIN: TNOTIFYEVENT

---- happened before the start of the download page.

Third, two examples of applying IE browser controls in the Delphi program

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

---- We use IE browser controls to make a help system for users, help files consist of multiple HTML files, one topic corresponds to an HTML file (Topic.htm), and the project under each topic corresponds to the HTML file. A tag (#item). This way in our system, you don't have to call the IE browser or WinHelp program to help users. I believe you know the advantage of the HTML help file with the traditional HLP help file.

---- In the following example, the method of use of the NaviGate method of the TWebBrowser (IE4 browser control) is demonstrated. Please note the comments in the program. (The following is the main segment of the program).

{Calling help files based on topics and projects}

Procedure Showhelp

Helptopic, HelpItem: String;

VAR

TargetFramename, PostData,

HEADS, FLAGS: Olevariant;

URL: WideString;

Begin

TargetFraMename: = ''; {Specify the empty string of frame,

Open help files in the current Frame}

PostData: = false; {does not send data}

HEADS: = ''; {header information is empty}

Flags: = 0; {Flags is set to 0}

URL: = Helptopic '.htm #' HelpItem;

{Help information URL}

With formhelp.Webbrowser do {in the help window

Help information in IE IE

Begin

NaviGate (URL, Flags, TargetFramename,

PostData, Heads; {Display Help Information}

END;

END;

---- (2) Show a GIF animation

---- If you still have no suitable animation display control, try the way below.

Procedure showgif (giffileename: string);

VAR

Targetframename, PostData, Heads, Flags: olevariant;

URL: WideString;

Begin

TargetFraMename: = ''; {Specify the empty string of frame,

Open the animation file in the current Frame}

PostData: = false; {does not send data}

HEADS: = ''; {header information is empty}

Flags: = 0; {Flags is set to 0}

URL: = GIFFILENAME;

WITH FORMGIF.WEBBBROWSER DO {Display Animation in IE in the Specified Window

Begin

NaviGate (URL, Flags, TargetFramename

, Poster, heads; {display animation file}

END;

END;

---- The above program is debugged under PWIN98 Delphi3.0.

转载请注明原文地址:https://www.9cbs.com/read-3957.html

New Post(0)