⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apc.htm

📁 delphi自学的好教材!特别适合刚刚起步学习delphi的人员!同样对使用者具有参考价值!
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD><SCRIPT LANGUAGE="JavaScript"><!--function popUp(pPage) { var fullURL = document.location; var textURL = fullURL.toString(); var URLlen = textURL.length; var lenMinusPage = textURL.lastIndexOf("/"); lenMinusPage += 1; var fullPath = textURL.substring(0,lenMinusPage); popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394'); figDoc= popUpWin.document; zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>'; zhtm += '</head>'; zhtm += '<BODY bgcolor="#FFFFFF">'; zhtm += '<IMG SRC="' + fullPath + pPage + '">'; zhtm += '<P><B>' + pPage + '</B>'; zhtm += '</BODY></HTML>'; window.popUpWin.document.write(zhtm); window.popUpWin.document.close(); // Johnny Jackson 4/28/98 }//-->                                                                </SCRIPT><link rel="stylesheet" href="/includes/stylesheets/ebooks.css">	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">	<TITLE>Teach Yourself Borland Delphi 4 in 21 Days -- Appendix C -- Building Internet Applications</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><CENTER><H1><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"></H1></CENTER><CENTER><H1><BR>Teach Yourself Borland Delphi 4 in 21 Days</H1></CENTER><CENTER><P><A HREF="../apb/apb.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../index.htm"><IMGSRC="../button/contents.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Contents"BORDER="0"></A> <HR></CENTER><CENTER><H1>- Bonus -</H1></CENTER><CENTER><H1>Building Internet Applications</H1></CENTER><UL>	<LI><A HREF="#Heading1">Internet Components Available in Delphi</A>	<LI><A HREF="#Heading2">Building a Web Browser</A>	<UL>		<LI><A HREF="#Heading3">Who Needs Yet Another Browser?</A>		<LI><A HREF="#Heading4">First Steps in Building Your Browser</A>		<LI><A HREF="#Heading5">Adding a Progress Indicator</A>		<LI><A HREF="#Heading6">Some Finishing Touches</A>	</UL>	<LI><A HREF="#Heading7">Using Internet Explorer as an ActiveX Control</A>	<LI><A HREF="#Heading8">Sending Mail</A>	<LI><A HREF="#Heading9">Deploying Internet Applications</A>	<LI><A HREF="#Heading10">Summary</A>	<LI><A HREF="#Heading11">Workshop</A>	<UL>		<LI><A HREF="#Heading12">Q&amp;A</A>		<LI><A HREF="#Heading13">Quiz</A>	</UL>	<LI><A HREF="#Heading14">Exercises</A></UL><P><HR SIZE="4"><CENTER><H1></H1></CENTER><P>Are you one of those people who think the Internet is just a fad, something thatwill never last? If so, let me tell you something...you're wrong! The Internet ishuge and it's getting bigger every day. In part, the Internet is about the Web andabout people spending hour after hour browsing the Web. But the Internet is alsoabout file transfers, email, and electronic commerce. The Internet is big business.It isn't going away anytime soon, so you might want to polish your Internet programmingskills. Thankfully, Delphi makes it easy to experiment with Internet programmingand to do serious Internet programming as well.</P><P>Today, you look at some aspects of Internet programming with Delphi. There's awhole world waiting out there on the Internet, so let's get to it.</P><P><H2><A NAME="Heading1"></A>Internet Components Available in Delphi</H2><P>The Internet components in Delphi are located on the Internet page of the Componentpalette and come in two categories. The first category is a group of components providedby NetMasters. With one exception, these are native VCL components. The exceptionis the THTML control, which is an ActiveX control. Table BD.1 lists the NetMasterscontrols and provides a description of each control. The controls are listed in theorder in which they appear on the Component palette.</P><P><H4>TABLE BD.1. NETMASTERS ACTIVEX INTERNET CONTROLS.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Control</I></TD>		<TD ALIGN="LEFT"><I>Description</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMDayTime</TD>		<TD ALIGN="LEFT">Obtains the date and time from Internet daytime servers.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMEcho</TD>		<TD ALIGN="LEFT">Sends text to and receives text from Internet echo servers.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMFinger</TD>		<TD ALIGN="LEFT">Obtains information about a user from an Internet finger server.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMFTP</TD>		<TD ALIGN="LEFT">Performs file transfers between networked machines using FTP (File Transfer Protocol).</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMHTTP</TD>		<TD ALIGN="LEFT">Performs file transfers using HTTP (Hypertext Transport Protocol). Hypertext documents			are normally viewed in a Web browser. You use THTTP to retrieve Web documents that			don't need to be displayed in a Web browser.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMMsg</TD>		<TD ALIGN="LEFT">Sends simple ASCII text messages using TCP/IP.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMMSGServ</TD>		<TD ALIGN="LEFT">Receives messages sent with the TNMMsg control.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMNNTP</TD>		<TD ALIGN="LEFT">Sends messages to and receives messages from Internet news servers using NNTP (Networking			News Transfer Protocol).</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMPOP3</TD>		<TD ALIGN="LEFT">Retrieves email messages from mail servers using POP3 (Post Office Protocol).</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMUUProcessor</TD>		<TD ALIGN="LEFT">Encodes or decodes MIME or uuencoded files.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMSMTP</TD>		<TD ALIGN="LEFT">Sends email through SMTP (Simple Mail Transfer Protocol) mail servers.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMStrm</TD>		<TD ALIGN="LEFT">Sends data streams to a network or Internet stream server.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMStrmServ</TD>		<TD ALIGN="LEFT">Receives streams sent by the TNMStrm control.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMTime</TD>		<TD ALIGN="LEFT">Obtains the date and time from Internet time servers.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMUDP</TD>		<TD ALIGN="LEFT">Transfers data across networks using UDP (User Datagram Protocol).</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TPowersock</TD>		<TD ALIGN="LEFT">Encapsulates the Winsock API.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMGeneralServer</TD>		<TD ALIGN="LEFT">Used for general TCP/IP servers.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">THTML</TD>		<TD ALIGN="LEFT">Displays HTML (Hypertext Markup Language) files. This is a Web</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"></TD>		<TD ALIGN="LEFT">browser component.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TNMURL</TD>		<TD ALIGN="LEFT">Converts URL data to a readable string and string data to URL format.</TD>	</TR></TABLE></P><P>The second category of controls includes native VCL components provided by Borland.The TClientSocket and TServerSocket components come with both the Professional andClient/Server versions of Delphi. The Web Broker components (TWebDispatcher, TPageProducer,TQueryTableProducer, and TDataSetTableProducer) come with only the Client/Serverversion. The VCL Internet components are listed in Table BD.2.</P><P><H4>TABLE BD.2. NATIVE VCL INTERNET COMPONENTS.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Component</I></TD>		<TD ALIGN="LEFT"><I>Description</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TClientSocket</TD>		<TD ALIGN="LEFT">Manages a TCP/IP client socket connection.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TServerSocket</TD>		<TD ALIGN="LEFT">Manages a TCP/IP server socket connection.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TWebDispatcher</TD>		<TD ALIGN="LEFT">Converts an ordinary data module to a Web module.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TPageProducer</TD>		<TD ALIGN="LEFT">Enables building of dynamic HTML pages.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TQueryTableProducer</TD>		<TD ALIGN="LEFT">Takes TQuery results and generates an HTML document from them.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TDataSetTableProducer</TD>		<TD ALIGN="LEFT">Takes TDataSet records and generates an HTML document from them.</TD>	</TR></TABLE></P><P>These two groups of controls give you all the power you need to build high-qualityInternet applications.</P><P><H2><A NAME="Heading2"></A>Building a Web Browser</H2><P>One of the most visible Internet programming tasks is building a Web browser.Certainly it's the most glamorous. The good news is that it can also be the easiest.</P><P><H3><A NAME="Heading3"></A>Who Needs Yet Another Browser?</H3><P>You might be wondering why anyone would want to build a Web browser. After all,the world already has Netscape Navigator and Internet Explorer, so who needs anotherbrowser? True enough, you probably aren't going to try to build a Web browser thatcompetes with Netscape or Microsoft. On the other hand, consider a company that hashundreds or even thousands of employees who need access to the Web. It can be verycostly to license thousands of copies of a commercial Web browser. On the other hand,you can write a quality Web application with Delphi in just a few hours, therebysaving the company a lot of money.</P><P>Another reason a company might want a custom Web browser is to restrict accessto the Web. For example, there might be sites on the Internet that employees haveto visit from time to time. A custom Web browser enables access to authorized siteson the Web but not to any other (unauthorized) sites. In fact, a custom browser isperfect for your kids!</P><P>Finally, one of the most compelling reasons for a custom Web browser is an <I>intranet</I>.An intranet is a Web site that is local to a particular network. An intranet cancontain a variety of information for a company's internal use--information on companybenefits, company policies, an employee address book, meeting schedules, or eveninformation on the company bowling league. A custom Web application can provide accessto an intranet and prevent access to the Internet.</P><P>So with that in mind, you'll build a simple Web browser. You'll probably be surprisedhow easy it is.</P><P><H3><A NAME="Heading4"></A>First Steps in Building Your Browser</H3><P>The THTML control is a ready-to-use Web browser. All you have to do is place oneof these controls on a form and call the RequestDoc method. Well, that might be alittle oversimplified, but you can display a Web document from anywhere on the Internetas easily as that. With that in mind, let me show you how quickly you can write aWeb browser application. Here are the first steps:</P><DL>	<DT></DT>	<DD><B>1. </B>Start with a new application. Change the form's Name property to WebMain	and the Caption property to EZ Web Browser.	<P>	<DT></DT>	<DD><B>2. </B>Place a Panel component on the form and change its Align property to	alTop and its Height property to 60. Clear the Caption property.	<P>	<DT></DT>	<DD><B>3. </B>Place a ComboBox component on the panel. Move it near the top of the	panel and make it as wide as the panel itself. Change the Name property to URLComboBox.	Change the Text property to an URL of your choice (try http://www.turbopower.com).	Double-click the Constraints property and change the AnchorHorz constraint to akStretch.	<P>	<DT></DT>	<DD><B>4. </B>Place a StatusBar component on the form. It will automatically position	itself at the bottom of the form. Change its Name property to StatusBar and its SimplePanel	property to True.	<P>	<DT></DT>	<DD><B>5. </B>Place an HTML control in the middle of the form. Change its Align property	to alClient. The HTML control fills the screen. Change the Name property to HTML.	<P>	<DT></DT>	<DD>Now your form should look similar to the one shown in Figure BD.1. If your application	doesn't look exactly like Figure BD.1, adjust as necessary or just leave it. (A little	individuality isn't a bad thing, after all.)</DL><UL>	<LI>At this point, you should save the project. Save the form as WebBrwsU.pas and	the project as WebBrows.dpr. Now you'll add just enough functionality to make the	browser do something useful.</UL><P><A HREF="javascript:popUp('28672201.gif')"><B>FIGURE BD.1.</B></A><B> </B><I>Yournew Web browser after the first steps.</I></P><DL>	<DT><I></I></DT>	<P>	<DD><B>6. </B>Click on the URL combo box. Generate an event handler for the OnClick	event. Type the following code in the event handler:	<P></DL><BLOCKQUOTE>	<PRE>if URLComboBox.Text &lt;&gt; `' then  HTML.RequestDoc(URLComboBox.Text);</PRE></BLOCKQUOTE><PRE></PRE><DL>	<DT></DT>	<DD>The RequestDoc method loads the requested document after first checking that	the combo box contains text.	<P>	<DT></DT>	<DD><B>7. </B>Now generate an event handler for the OnKeyPress event. Type the following	code in the event handler:	<P></DL><BLOCKQUOTE>	<PRE>if Key = Char(VK_RETURN) then begin  Key := #0;  if URLComboBox.Text = `' then    Exit;  URLComboBoxClick(Sender);end;</PRE></BLOCKQUOTE><PRE></PRE><DL>	<DT></DT>	<DD>This code first checks the Key parameter to see whether the Enter key was pressed.	If so, it sets Key to 0 and calls the URLComboBoxTest method (created in step 6).	Setting Key to 0 prevents the speaker from beeping when the Enter key is pressed.	The call to the URLComboBoxClick method loads the URL into the Web browser.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -