A web browser with all links on the web page is automatically found. Overview Web applications have been deeply roofed to the present society, as a software developer or other technicians, it is possible to meet a lot of information and information on the Internet. Generally, the most used is web search Engine. . When we use it to find a lot of information links, there may be more links, but you have to see if they are links, that is really a very troublesome thing. This article is to talk about how to use Delphi's mshtml_tlb.pans to develop a simple web browser with all links on the web page. I am in the environment in IE5, of course it can be compatible, such as IE4.2. About MSHTML_TLB.PASMSHTML_TLB.PAS is a class inside Deliphi. Its meaning is the Microsoft HTML object library. It cannot be included in all engineering or programs because it is too big, and the code of the entire file has 241,899L line, so long. The size is about 12m. Let's take a look at how it is added to the program. 1. First, we open Delphi to create a new Application. I saved Form1 as mainfrm.pas, saved Application as Findlinks.dpr.2. What is the implementation of the Microsoft HTML object library (MSHTML TYPE LIBRARY.) To implement IE. Figure 1, Project-> Import Type Library:
Then you will see a list of "Microsoft HTML Object Library, as shown in Figure 2. Some problems may be encountered next. For example, there is no "Microsoft HTML Object Library" in the list. Why is this? That is the issue of IE, because IE version is different (I use IE5). I suggest that you first query your computer with a mshtml.tlb file. Inside the 9X it exists with the C: / Windows / System directory, it is in / Winnt / System32 directory in 2000. If you find this file, you can use the Click on the "add ..." button of Figure 2, then select MSHTML.TLB, you can, if you don't find it, you don't have IE or your IE version. Low, please upgrade IE. Finally, when we chose the pouring library, we will wait for a while, because it is too long, but please don't be because it is a crash. It will provide a lot of help to automatic lookup. 3. Project implementation. The interface is designed as shown below:
Use the following components: Control Namedttlabel LBLURL Data URL TEDIT EDTURL HTTP: //www.huihu.comtbutton BTNFindLinks Query TListbox Lstbxlinks Null
4. Program design 1. In the INTERFACE section of the Form1, add, OleCtrls, SHDOCVW, and OLECTRLS, SHDOCVW, and OleServer. These applications are based on TinterNeTexplorer we have to create, which is an object of the ActiveX of IE. But there are other ways (TINTERNETEXPLORER), and we use TWebBrowser to control our Form1.2. We add as follows: FinterneTexplorer: TINTERNETEXPLORER: TINTERNETEXPLORER; Procedure WebBrowserDocumentComplete (Sender: Tobject; Var PDISP: Olevariant; var URL: Olevariant); Finally use Ctrl-Shift-C to complete classes. 3. Add as follows: Uses mshtml_tlb, COMOBJ; class to use. 4. Add the following: FinterneTexplorer: = TINTERNETEXPLORER.CREATE (Self); FinterNeTexplorer.ondocumentComplete: = WebBBrowserDocumentComplete; 5. Finally, there was added the following code TForm1.WebBrowserDocumentComplete of form1: 1 procedure TForm1.WebBrowserDocumentComplete. (Sender:. TObject; 2 var pDisp: OleVariant; var URL: OleVariant); 3 var4 Doc:. IHTMLDocument2; 5 ElementCollection:.. IHTMLElementCollection; 6. htmlelement: htmlelement; 7. I: integer; 8. Anchorstring: string; 9. Begin10. LstbxLinks.clear; 11. // When processing the web page, it is found that it is not fully downloaded, and will not process 12. DOC : = FInternetExplorer.Document as IHTMLDocument2; 13 if Doc = nil then14 raise Exception.Create ( 'Couldn''t convert the' 15 'FInternetExplorer.Document to an IHTMLDocument2'.); 16 // captured on the web... All elements. 17. ElementCollection: = doc.all; 18. For i: = 0 to elementCollection.Length - 1 do19. Begin20. File: // Get the current element 21. HTMLELEMENT: = ElementCollection.Item (i, '') as htmlelement ; 22. // Find the LINK tag in the web rated code.
23. // Discover other HTML tags (for example: Table, Font, ETC.) 24. If htmlelement.tagname = 'a' Then25. Begin26. // Crawl Innertext in detail LINK, Innertext is the Finally, we join the OnClick event in Button (btnfindlinks): 1. Instrument in the browse web is queried. 2. FinterneTexplorer.navigate (EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam); From the above program we can see that it is actually very simple, people who have seen HTML original code know, The code that causes the web page to connect to: Southwestern National College b> The principle of my program is to intercept HREF back The string and the "" "" is closed later. Then save it as another string. Then it is displayed by TWebBrowser. Finally let us compile this program, but compile it, because compile 241,899L's MSHTML_TLB.PAS is a very troublesome thing. It also includes up to more than 20 Warning errors, but please feel relieved. This is the problem with mshtml_tlb.pas. It is not related to other procedures. Such a small lookup Web The simple web browser on the page appears in front of us. This program is compiled under IE5.0 and Delphi6.