---- Maybe you still remember the browser example in Delphi's sample program. In that example, a browser was made using the properties and methods of the control THttp. This example is really good for understanding how to use the THttp control. But few people will use it as a real browser. The reason is very simple. The functions are too limited, it does not support Frame, does not support Script scripting language, cannot view HTML files as local files, etc. Most users are using IE or Navigator; we programmers are also happy to use ready-made browsers. When we need to use the browser, we call the external browser in the program through methods such as WinExec or CreatePRocess for users to use. This method is indeed very trouble-free, but it always makes me a little unwilling to give up program control to other external programs. It always makes me very troublesome, especially when the computer usage level of the user of the application software is not very high. It would be great if there was a browser control that allowed you to embed the browser into your own program.
---- If the external environment of your software is WIN95+IE or WIN98 (the usage rate of such software is still very high), then there is already an IE browser control in the system that can be used. Maybe you have long You haven't noticed the time, don't waste resources, use them. When IE 3.X or IE 4. , you will find that the IE control has been registered in the system as an ActiveX control, so that we can use the control in Delphi.
---- Since the IE browser control needs to provide a display function before it can be used, you cannot use CreateOleObject to obtain an instance in the program and directly use its properties and methods, otherwise the program will cause an error when running; in this case, you need to use the functions provided in Delphi "Import ActiveX Control" function, the operation method is described below.
---- In the "Components" menu, call the "Import ActiveX Control" function, select "Microsoft Internet Controls (Version1.1)" in the Registered Controls list, and the path shown in the prompt bar below is C:PWin98SystemSHDOCVW.DLL, three controls that can be registered are listed in Class Names (type list): TWebBrowser_V1, TWebBrowser and TShellFolderViewOC are IE3 browser control, IE4 browser control and "Microsoft Shell Folder View Router" control respectively. Click Install to install. After the installation is completed, three controls will be added in the "ActiveX" control bar, namely TWebBrowser_V1, TWebBrowser and TShellFolderViewOC; in Delphi's Imports directory, a file SHDocVw_TLB.PAS will be created, which contains the packaging details of these three controls. , of course, contains descriptions of the properties and methods of the control, which can be used as a reference for us to use the control.
----
Take TWebBrowser (IE4 browser control) as an example. The common properties and methods of TWebBrowser mainly include: GoBack: method, go back to the previous page. GoForward: method to advance to the next page. GoHome: Method, calls the default home page, which is set in the IE options. GoSearch: Method, calls the default search page, which is set in the IE options. Navigate(const URL: WideString; var Flags, TargetFrameName, PostData, Headers: OleVariant): method, calls the specified page, the specific parameters are as follows: URL: the URL of the specified page. Flags: Word type, the function is not clear yet, can be set to 0. TargetFrameName: WideString, open the Frame where the page is located. If it is an empty string, it will be opened in the current Frame; if the Frame specified by TargetFrameName exists, it will be opened in the Frame; if the Frame specified by TargetFrameName does not exist, a new window will be opened. This is equivalent to For calling the external IE browser. PostData: boolean, whether to allow sending data. Headers: WideString, the header data of the URL request to be sent. Refresh: method, refresh the current page. Stop: Method, stop calling or opening the current page. LocationName: Property (WideString), the name of the current location. LocationURL: Property (WideString), the URL of the current location. Busy: Attribute (Boolean), whether it is busy. Visible: Property (Boolean), whether the browser window is visible. (The following properties are new in TWebBrowser and are not available in TWebBrowser_V1, and their functions need to be explored) StatusBar: Property (Boolean), whether to display the status bar. StatusText: Property (WideString), status bar content. ToolBar: Property (SYSINT), content in the toolbar. MenuBar: Property (Boolean), whether to display the menu bar. FullScreen: Property (Boolean), whether to display in full screen. Offline: Property (Boolean), whether to browse offline. AddressBar: Property (Boolean), whether to display the address bar. Common events of TWebBrowser mainly include: OnStatusTextChange = procedure(Sender: TObject; const Text: WideString) of object;
---- Occurs when the status bar prompt information changes. The parameter Text is the current status bar prompt information. We can update our own status bar prompt information or handle other transactions based on this information.
----OnProgressChange = procedure(Sender: TObject; Progress, ProgressMax: Integer) of object;
---- Occurs when the progress of the open page changes. The parameter Progress is the current progress and 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;
---- Occurs when a new command is executed. Command is the command identifier, and Enable is whether the command is allowed to be executed. OnTitleChange = procedure(Sender: TObject; const Text: WideString) of object;
---- Occurs when the title of the page changes, Text is the current title.
----OnPropertyChange = procedure(Sender: TObject; const Property_: WideString) of object;
---- Occurs when the properties of the page change, Property_ is the property name OnDownloadComplete: TNotifyEvent
---- Occurs after the download page is completed.
----OnDownloadBegin: TNotifyEvent
---- Occurs before the download page starts.
---- (1) Make your own help system
---- We use the IE browser control to create a help system for users. The help file is composed of multiple HTML files. One topic corresponds to one HTML file (Topic.HTM), and the items under each topic correspond to the HTML files. A tag (#Item). In this way, in our system, we no longer need to call the IE browser or WinHelp program to provide help to users. I believe you all know the advantages of HTML help files compared with traditional HLP help files.
---- In the following example, the use of the Navigate method of TWebBrowser (IE4 browser control) is demonstrated. Please pay attention to the comments in the program. (Below is the main snippet of the program).
{Calling the help file according to the topic and project}procedure ShowHelp(HelpTopic,HelpItem: String);var TargetFrameName,PostData,Heads,Flags:OleVariant;URL:widestring;begin TargetFrameName:= ';{When specifying the empty string of Frame, then Open the help file in the current Frame} PostData := false;{Do not send data} Heads := ';{Header information is empty} Flags := 0;{Flags is set to 0} URL := HelpTopic + '.HTM#'+HelpItem;{URL of help information} 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;end;
---- (2) Display a GIF animation
---- If you don't have a suitable animation display control, you might as well try the following method.
procedure ShowGIF( GIFFileName : String );var TargetFrameName,PostData,Heads,Flags : OleVariant; URL : widestring;begin TargetFrameName := ';{When specifying the empty string of Frame, the animation file will be opened in the current Frame} PostData := false;{Do not send data} Heads := ';{Header information is empty} Flags := 0;{Flags is set to 0} URL := GIFFileName; with formGIF.webbrowser do{Display animation in the IE browser control in the specified window} begin navigate(URL,Flags,TargetFrameName,PostData,Heads);{Display animation file} end;end;
----The above program has been debugged under PWIN98+Delphi3.0.