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

📄 ch21.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 -- Ch 21 -- Delphi and C++Builder</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="../ch20/ch20.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../apa/apa.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <HR></CENTER><CENTER><H1>- 21 -</H1></CENTER><CENTER><H1>Delphi and C++Builder</H1></CENTER><UL>	<LI><A HREF="#Heading1">Similarities Between Delphi and C++Builder</A>	<UL>		<LI><A HREF="#Heading2">The IDE</A>		<LI><A HREF="#Heading3">The Visual Component Library</A>		<LI><A HREF="#Heading4">Form Files</A>		<LI><A HREF="#Heading5">Packages</A>	</UL>	<LI><A HREF="#Heading6">Differences Between Delphi and C++Builder</A>	<UL>		<LI><A HREF="#Heading7">Language</A>		<LI><A HREF="#Heading8">Filename Extensions</A>		<LI><A HREF="#Heading9">IDE</A>	</UL>	<LI><A HREF="#Heading10">Code Editor</A>	<UL>		<LI><A HREF="#Heading11">Code Explorer</A>	</UL>	<LI><A HREF="#Heading12">VCL Enhancements</A>	<UL>		<LI><A HREF="#Heading13">C++Builder Can Compile Pascal Units</A>		<LI><A HREF="#Heading14">ActiveX Support</A>		<LI><A HREF="#Heading15">Delphi Compiles Faster and Produces Smaller EXEs</A>	</UL>	<LI><A HREF="#Heading16">Converting from Delphi to C++Builder</A>	<UL>		<LI><A HREF="#Heading17">Copying the Delphi Forms</A>		<LI><A HREF="#Heading18">Converting the Code</A>		<LI><A HREF="#Heading19">The Pascal as Statement</A>		<LI><A HREF="#Heading20">Reusing Forms</A>	</UL>	<LI><A HREF="#Heading21">Summary</A>	<LI><A HREF="#Heading22">Workshop</A>	<UL>		<LI><A HREF="#Heading23">Q&amp;A</A>	</UL>	<LI><A HREF="#Heading24">Quiz</A>	<UL>		<LI><A HREF="#Heading25">Exercises</A>	</UL>	<LI><A HREF="#InReview">In Review</A></UL><P><HR SIZE="4"><CENTER><H1></H1></CENTER><P>When Borland released Delphi 1 a few years ago, it was a huge success. Now onversion 4, Delphi continues to be a huge success today. Sometime after Delphi 2,Borland decided to leverage the success of Delphi by creating a RAD development environmentfor C++. Borland leveraged that success in more ways than one. One way was by reusingparts of Delphi in C++Builder. In this chapter you learn about how Delphi and C++Builderare similar and how they are different. You also learn how to exchange code betweenDelphi and C++Builder and how to convert code from C++Builder to Delphi.</P><P><H2><A NAME="Heading1"></A>Similarities Between Delphi and C++Builder</H2><P>Delphi and C++Builder are more similar than they are different. Let's look atthose similarities in the following sections.</P><P><H3><A NAME="Heading2"></A>The IDE</H3><P>If you have used both Delphi and C++Builder, you might have been struck by howsimilar their Integrated Development Environments (IDEs) are. Those of you who haven'tused both Delphi and C++Builder (and even those who have), take a look at Figures21.1 and 21.2. One of these figures is a screen shot of Delphi 3 and the other isa screen shot of C++Builder 3. I have removed the icons and program name from thetitle bars so that it isn't immediately apparent which is which. Can you tell thedifference?</P><P><A HREF="javascript:popUp('28672101.gif')"><B>FIGURE 21.1.</B></A><B> </B><I>Delphior C++Builder?</I></P><P><A HREF="javascript:popUp('28672102.gif')"><B>FIGURE 21.2.</B></A><B> </B><I>Delphior C++Builder?</I></P><P><I><BR></I>Do you give up? Figure 21.1 shows the Delphi IDE and Figure 21.2 shows the C++BuilderIDE. If you have used both Delphi and C++Builder, you might have recognized fromthe Object Inspector which figure shows the Delphi IDE and which shows the C++BuilderIDE. The Delphi Object Inspector shows properties with values of True and False,whereas the C++Builder Object Inspector shows true and false.</P><PRE></PRE><P>The point of this exercise is that the IDEs of C++Builder 3 and Delphi 3 are nearlyidentical. (You might have noticed I used Delphi 3 for this illustration rather thanDelphi 4. I used Delphi 3 because I wanted to compare it with C++Builder 3, the latestversion of C++Builder at the time of this writing, and the version that correspondsto Delphi 3.)</P><P>When you start examining the menus, you will see some differences, naturally,but for the most part the IDEs are so similar that if you know how to use one ofthese development environments, you know how to use the other. This has obvious benefits.For example, let's say your company has been using Delphi and now wants to add C++to its toolset. Using C++Builder as your C++ development tool saves you time andmoney because your programmers don't have to learn a new development environment.That leads to another similarity between Delphi and C++Builder: the Visual ComponentLibrary.</P><P><H3><A NAME="Heading3"></A>The Visual Component Library</H3><P>Not only are the IDEs of Delphi and C++Builder nearly identical, but they alsoshare the exact same component library in the VCL. The VCL is written in Object Pascal,but both Delphi and C++Builder share the same VCL (with some minor differences thatI address later in the section, &quot;VCL Enhancements&quot;).</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> There has been a fair amount of discussion on the Borland newsgroups	among C++ programmers on the subject of a Pascal component library in a C++ development	environment. Some C++ programmers can't get over the fact that the VCL is written	in Object Pascal. Most programmers, though, take the sensible approach of not caring	what language the VCL is written in. They just want to get their work done on time	and within budget. For these programmers, the added productivity of C++Builder far	outweighs the language issue. <HR></BLOCKQUOTE><P>The fact that both Delphi and C++Builder use the same framework is again a hugebenefit if you use both Delphi and C++Builder. Other than the syntactical differencesbetween Object Pascal and C++, the VCL components are used identically in the twoIDEs. Take the following Delphi code:</P><P><PRE>if OpenDialog1.Execute then  Memo1.Lines.LoadFromFile(OpenDialog1.FileName);</PRE><PRE>Now look at the C++Builder equivalent:</PRE><PRE>if (OpenDialog1-&gt;Execute())  Memo1-&gt;Lines-&gt;LoadFromFile(OpenDialog1-&gt;FileName);</PRE><P>As you can see, there is no difference in the use of VCL. The only differencesare the differences between C++ syntax and Object Pascal syntax. This means thatyou don't have to learn a new framework if you want to switch between Delphi andC++Builder, or vice versa. For a company with a large number of programmers, thismeans that you can leverage your programmers' knowledge to the maximum. Even if youare a single programmer, knowing both Delphi and C++Builder is very valuable.</P><P><H3><A NAME="Heading4"></A>Form Files</H3><P>The form files used in Delphi and C++Builder are also identical. You can createa form in Delphi and reuse that form in C++Builder. Later I will explain exactlyhow to do that in the section &quot;Reusing Forms.&quot; Although creating formsin Delphi and C++Builder is easy, it still takes time to design and create complexforms. By reusing your forms, you don't have to repeat work that has already beendone.</P><P><H3><A NAME="Heading5"></A>Packages</H3><P>Both Delphi and C++Builder use packages. In almost all cases, packages createdfor Delphi can be used in C++Builder. They will probably have to be recompiled inC++Builder, but that is a trivial task. The capability of C++Builder to use Delphipackages means that you have a wealth of commercial, shareware, and freeware VCLcomponents available to you. These components are almost always written with Delphi,so they can be used in both Delphi and C++Builder. At this time you cannot use packageswritten for C++Builder in Delphi, but that might change with the later versions ofthese two products.</P><P><H2><A NAME="Heading6"></A>Differences Between Delphi and C++Builder</H2><PRE>Although Delphi and C++Builder have many similarities, they also have many differences. Most of the differences are a result of the variations in the Object Pascal and C++ languages.</PRE><P>Other differences are due to what I like to call the &quot;leapfrog effect.&quot;In the beginning there was Delphi 1. After that, naturally, came Delphi 2. AfterDelphi 2 was released, Borland began working on C++Builder. C++Builder 1 was patternedafter Delphi 2 (which was released about a year before C++Builder 1). As such, C++Builder1 acquired most of its features from Delphi 2. C++Builder 1 didn't add anything significantto what Delphi 2 offered--it was primarily a copycat. Shortly after C++Builder 1was released, Borland released Delphi 3.</P><P>C++Builder 3 followed (Borland skipped version 2 of C++Builder to match Delphi'sversion number). C++Builder 3 is patterned after Delphi 3, just as C++Builder 1 waspatterned after Delphi 2. However, C++Builder 3 added several features not foundin Delphi 3 (the Project Manager, for example). Delphi 4 inherited the features introducedin C++Builder 3 and, of course, added a number of new features. C++Builder 4 willlikely contain the new features of Delphi 4, will add more new features, and so on.This leapfrogging will likely continue for some time, with each release (whetherit be Delphi or C++Builder) gaining the benefit of the previous release and addingnew features of its own.</P><P>Now let's look at the differences between Delphi and C++Builder.</P><P><H3><A NAME="Heading7"></A>Language</H3><P>The most obvious difference between Delphi and C++Builder is that C++Builder generatesC++ code and Delphi generates Object Pascal code, which leads to variations in theIDEs of the two products. For example, Delphi has a menu item under the File menucalled Use Unit. C++ uses header files (.H or .HPP files) for each unit, so thatmenu item in C++Builder is called Include Unit Hdr. These types of differences aboundthroughout the two IDEs for obvious reasons.</P><P><H3><A NAME="Heading8"></A>Filename Extensions</H3><P>Delphi and C++Builder use different filename extensions for project and supportfiles. This is partly a result of the language differences between the two products.The contrasting filename extensions enable you to easily distinguish a Delphi filefrom a C++Builder file. Table 21.1 lists the various project elements and their respectivefile extensions for both Delphi and C++Builder.</P><P><H4>TABLE 21.1. DELPHI AND C++BUILDER FILE EXTENSIONS.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Element</I></TD>		<TD ALIGN="LEFT"><I>Delphi</I></TD>		<TD ALIGN="LEFT"><I>C++Builder</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Project file</TD>		<TD ALIGN="LEFT">.DPR</TD>		<TD ALIGN="LEFT">.BPR</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Project group file</TD>		<TD ALIGN="LEFT">.BPG</TD>		<TD ALIGN="LEFT">.BPG</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Source file</TD>		<TD ALIGN="LEFT">.PAS</TD>		<TD ALIGN="LEFT">.CPP</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Header file</TD>		<TD ALIGN="LEFT">None</TD>		<TD ALIGN="LEFT">.H or .HPP</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Form file</TD>		<TD ALIGN="LEFT">.DFM</TD>		<TD ALIGN="LEFT">.DFM</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Compiled binary file</TD>		<TD ALIGN="LEFT">.DCU</TD>		<TD ALIGN="LEFT">.OBJ</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Compiled resources</TD>		<TD ALIGN="LEFT">.RES or .DCR</TD>		<TD ALIGN="LEFT">.RES</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Saved desktop settings</TD>		<TD ALIGN="LEFT">.DSK</TD>		<TD ALIGN="LEFT">.DSK</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Project options</TD>		<TD ALIGN="LEFT">.DOF</TD>		<TD ALIGN="LEFT">None</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Package source files</TD>		<TD ALIGN="LEFT">.DPK</TD>		<TD ALIGN="LEFT">.BPK</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Compiled package</TD>		<TD ALIGN="LEFT">.BPL</TD>		<TD ALIGN="LEFT">.BPL</TD>	</TR></TABLE></P><P>Notice that in some cases the filename extensions used by Delphi and C++Builderare the same.</P><P><H3><A NAME="Heading9"></A>IDE</H3><P>The Delphi 4 IDE is brand new. In particular, the following features are new tothe Delphi 4 IDE and are not found in the current version of C++Builder:</P><UL>	<LI>Dockable menu, toolbars, and Component palette	<P>	<LI>New button bitmaps for the IDE toolbar buttons	<P>	<LI>Bitmaps for key menu items	<P>	<LI>Dockable tool windows</UL><P>Some of the IDE enhancements listed here are cosmetic (hey, it doesn't hurt togive an application a facelift every once in awhile!). Other enhancements, such asthe dockable toolbars, menus, and tool windows, are productivity boosters.</P>

⌨️ 快捷键说明

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