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

📄 ch02.htm

📁 好书《C++ Builder高级编程技术》
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>

<HEAD>
	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
	<META NAME="Author" Content="Steph Mineart">
	<TITLE>Ch 2 -- Basic Facts About C++Builder</TITLE>
</HEAD>

<BODY 
BACKGROUND="bg1.gif" tppabs="http://pbs.mcp.com/ebooks/0672310228/buttonart/bg1.gif" BGCOLOR="#FFFFFF">

<P ALIGN="CENTER"><IMG SRC="sams.gif" tppabs="http://pbs.mcp.com/ebooks/0672310228/buttonart/sams.gif" WIDTH="75" HEIGHT="24" ALIGN="BOTTOM"
BORDER="0"><BR>
<BR>
<A HREF="index-3.htm" tppabs="http://pbs.mcp.com/ebooks/0672310228/index.htm"><IMG SRC="toc.gif" tppabs="http://pbs.mcp.com/ebooks/0672310228/buttonart/toc.gif" WIDTH="40" HEIGHT="40" ALIGN="BOTTOM"

ALT="TOC" BORDER="0" NAME="toc4"></A><A HREF="ch01.htm" tppabs="http://pbs.mcp.com/ebooks/0672310228/ch01.htm"><IMG SRC="back-1.gif" tppabs="http://pbs.mcp.com/ebooks/0672310228/buttonart/back.gif"
WIDTH="40" HEIGHT="40" ALIGN="BOTTOM" ALT="BACK" BORDER="0" NAME="toc1"></A><A HREF="ch03.htm" tppabs="http://pbs.mcp.com/ebooks/0672310228/ch03.htm"><IMG
SRC="forward.gif" tppabs="http://pbs.mcp.com/ebooks/0672310228/buttonart/forward.gif" WIDTH="40" HEIGHT="40" ALIGN="BOTTOM" 
ALT="FORWARD" BORDER="0"
NAME="toc2"></A></P>
<H2 ALIGN="CENTER"><FONT COLOR="#000077">Charlie Calvert's C++ Builder Unleashed</FONT></H2>
<P>
<H2 ALIGN="CENTER"><A NAME="Heading1"></A><FONT COLOR="#000077">- 2 -</FONT></H2>
<H2 ALIGN="CENTER"><A 
NAME="Heading2"></A><FONT COLOR="#000077">Basic Facts About
C++Builder</FONT></H2>
<P>This chapter and the next five cover the basic facts that everyone needs to know
about BCB. Important subjects included in this chapter are as follows:

<UL>
	
<LI>The IDE
	<P>
	<LI>Projects
	<P>
	<LI>The VCL
	<P>
	<LI>Core VCL Technologies: Components, Properties, and Events
	<P>
	<LI>Stepping into the Pascal source for the VCL
	<P>
	<LI>The syntax of the VCL
	<P>
	<LI>An overview of the component 
architecture
	<P>
	<LI>A brief look at Run Time Type Information (RTTI)
</UL>

<P>This introduction to BCB continues in the next chapter, where I cover the new
Borland additions to the C++ language and introduce several key BCB classes such
as 
<TT>AnsiString</TT>s and <TT>Sets</TT>. These special classes emulate features
of Object Pascal. Then, in Chapter 4 you will have a look at events. Chapter 5 focuses
on exceptions, Chapter 6 on using Delphi code in BCB, and Chapter 7 on graphics 
programming
with the VCL. The latter chapter will complete my introduction to the VCL and to
the syntax that is common to almost all BCB programs.</P>
<P>When reading this chapter, you need to remember the basic philosophy of this book.
My goal here 
is not to plumb the depths of C++, the VCL, the Windows API, or any
other hardcore technical syntax. Instead, I want to show you how to quickly build
real-world applications without losing touch with the underlying Windows architecture.
In these 
chapters there are many times when I make a pass over very complicated subjects
such as C++ constructors, templates, rules of precedence, the GDI, and so on. I am,
of course, aware that these are sticky subjects that take many pages to cover 
appropriately.
However, you will not find in-depth discussions of these subjects in this book, for
there are many other volumes dedicated to those topics. Furthermore, the goal of
this book is to show how to use RAD tools and high-level objects to 
perform complicated
tasks quickly, easily, and safely.</P>
<P>C++ is already at least 10 times faster than interpreted languages such as Visual
Basic, Java, or PowerBuilder. If slowing down performance by five percent yields
a 10- or 20-fold increase 
in reliability or ease of use, I think it is worth it to
play a somewhat more cautious game. In my opinion, it is better to be nine times
faster and nearly as safe as an interpreted tool than it is to be 10 times faster
and 10 times more dangerous 
than an interpreted tool. That last 5 or 10 percent that
you can eke out of the language by using every imaginable trick just isn't worth
it, except in a few unusual circumstances such as compilers, operating systems, and
game engines. Even in those 
cases, it is still probably best to use the relatively
small and fast OOP-based techniques outlined in this book.</P>
<P>This particular chapter is unique in that it covers a number of technical subjects
that are not very complex. Everything in this 
chapter is here because I either

<UL>
	<LI>Think that you have to know it in order to complete BCB programs.
	<P>
	<LI>Think that you have to know it in order to feel at all comfortable inside the
	BCB programming environment.
</UL>

<P>Don't worry 
if you find most of the material in this chapter a bit too simplistic.
There is some basic material that almost has to be covered in a book of this type,
and once I get it out of the way, I will move on to more interesting subject matter
in the next 
chapters.</P>
<P>It's time now to get started with an overview of the BCB environment, project
management, the VCL, and the basic syntax used by BCB programmers. When you have
completed this and the next five chapters, you should have all the 
knowledge you
need to begin a robust, broad exploration of the all the exciting features found
in BCB.
<H3><A NAME="Heading4"></A><FONT COLOR="#000077">Creating C++Builder Projects</FONT></H3>
<P>C++Builder has a project manager that you can access 
from the View menu. You can
use this tool to add files to a project or to remove files from a project.</P>
<P>You can add files with the following extensions to your project, and C++Builder
will compile and/or link them automatically, as shown in 
Table 2.1: <BR>
<BR>
<B>Table 2.1. Files you can add to a BCB project. </B>
<TABLE BORDER="1">
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="103" ALIGN="LEFT"><B>Type of File</B></TD>
		<TD ALIGN="LEFT"><B>Description</B></TD>
	</TR>
	<TR ALIGN="LEFT" 
rowspan="1">
		<TD WIDTH="103" ALIGN="LEFT">CPP</TD>
		<TD ALIGN="LEFT">C++ Source module. OWL and MFC are treated in the appendices.</TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="103" ALIGN="LEFT">C</TD>
		<TD ALIGN="LEFT">C Source 
module.</TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="103" ALIGN="LEFT">PAS</TD>
		<TD ALIGN="LEFT">Any Pascal module that will compile in Delphi 2.01.</TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="103" ALIGN="LEFT">RC</TD>
		<TD 
ALIGN="LEFT">Resource script.</TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="103" ALIGN="LEFT">RES</TD>
		<TD ALIGN="LEFT">Resource file.</TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="103" ALIGN="LEFT">OBJ</TD>
		<TD 
ALIGN="LEFT">Compiled C++, C, or PAS file.</TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="103" ALIGN="LEFT">LIB</TD>
		<TD ALIGN="LEFT">C or C++ Library file.</TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="103" ALIGN="LEFT">DEF</TD>
		
<TD ALIGN="LEFT">Module Definition file.</TD>
	</TR>
</TABLE>
<BR>
<BR>
You can use the IDE to produce Windows executables, DLLs, or console applications:

<UL>
	<LI>To create a 32-bit Windows executable, you need do nothing. The default behavior
	of 
the IDE is to generate this type of executable.
	<P>
	<LI>To create a DLL, go to File | New and select DLL from the Object Repository.
	Click OK. Everything else is automatic. I discuss exporting functions from a DLL
	in several later chapters of the 
book, including Chapter 26, &quot;Extending an Internet
	Server with ISAPI.&quot; In a word, the key to exporting a method from a DLL is to
	use <TT>__declspec(dllexport)</TT>, as described in Chapter 26 and in the comments
	at the top of the file 
<TT>ISAPI1.CPP</TT> from Chapter 26.
	<P>
	<LI>To create a console application, go to the Options | Project | Linker option
	from the menu and select Console Application. If you want to create a console application
	as a quick way to produce text 
output, you should consider using the BCB <TT>TMemo</TT>,
	<TT>TListBox</TT>, and <TT>TEdit</TT> controls instead. I can output text to these
	controls at least as quickly as I can use <TT>printf</TT> or <TT>cout</TT>. I find
	these components are 
more useful than outputting text to the command line, because
	they support concepts like scrolling and saving their contents to a file or the clipboard.
</UL>


<DL>
	<DT></DT>
</DL>



<BLOCKQUOTE>
	<P>
<HR>
<FONT 
COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Delphi programmers need to remember
	that it is not enough merely to <TT>#include</TT> a C, CPP, or PAS file in a module
	of an existing project. You also have to add the file itself to the project using
	the 
Project Manager or the Add to Project menu choices or speed buttons. Delphi's
	linker assumed that you would not reference a file from your <TT>uses</TT> clause
	unless you wanted it to be part of your project. C++Builder, for better or worse,
	makes 
no such assumption. You must incorporate the new file into your makefile listing,
	or it will not be linked into your project. 
<HR>


</BLOCKQUOTE>

<P>BCB projects are managed in a standard C++ makefile. The easiest way to get something
into your 
makefile is through the project manager. Editing the makefile itself is
not recommended, but C++ experts will find there are some changes to your project
that can only be made by editing the makefile.</P>
<P>Most of the important changes which can be 
made to a makefile are configurable
through the Options | Project or Options | Environment menu choices. The developers
of BCB do not expect you to find many occasions when you will need to edit the makefile.
I believe the primary reason the makefile 
exists is that the team grew tired of trying
to manage a binary project file.</P>
<P>The Microsoft C++ team, on the other hand, recently grew tired of trying to manage
a text-based project file! This is probably one of those cases where developers 
have
a choice between two evils.</P>
<P>If you are trying to manage projects that consist of multiple executables and
DLLs, you will almost certainly find the current BCB project manager inadequate.
Borland C++ 5.02 will support compiling C++Builder 
projects. You will therefore want
to consider using the advanced tools in BC 5.02 for managing huge projects.</P>
<P>BC5 also supports a powerful scripting language not available in BCB. As a result,
I think some programmers will find a combination of 
BC5 and BCB to produce the ultimate
C++ programming environment.</P>
<P>Having made my pitch to that special group of programmers who are managing massive
projects, I want to end this section by stating that I find BCB includes everything
I need and 
considerably more. The goal of this book is to talk about completing high
quality projects as quickly and efficiently as possible. If that is your goal, stick
with BCB and with third-party tools tailored for this environment. BCB is the ideal
tool for 
creating C++ applications. It is state of the art and leagues ahead of any
other C++ environment that is planned or available at the time of this writing.
<H4><A NAME="Heading6"></A><FONT COLOR="#000077">BCB File Extensions</FONT></H4>
<P>In the last 
section, in Table 2.1, I list the types of files you can include in
C++Builder. Most of these files will be generated automatically for you by the compiler,
and I list them here just so you will know why they exist and what they do. In this
section, I 
will talk about all the important files that become part of your project.
Table 2.2 lists the key extensions in BCB projects. <BR>
<FONT SIZE="4"><B><BR>
</B></FONT><FONT COLOR="#000000"><B>Table 2.2. File types used in a BCB project.
</B></FONT>

<TABLE BORDER="1">
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="84" ALIGN="LEFT"><B>File extension</B></TD>
		<TD WIDTH="229" ALIGN="LEFT"><B>Description</B></TD>
		<TD ALIGN="LEFT"><B>File type</B></TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD 
WIDTH="84" ALIGN="LEFT">RC</TD>
		<TD WIDTH="229" ALIGN="LEFT">Source for resource file.</TD>
		<TD ALIGN="LEFT">Text</TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="84" ALIGN="LEFT" VALIGN="TOP">RES</TD>
		<TD WIDTH="229" 
ALIGN="LEFT">Resource file. There will usually be <BR>
			one RES file with the same name <BR>
			as your project that contains only an icon.<BR>
			It's best to leave this file alone.</TD>
		<TD ALIGN="LEFT" VALIGN="TOP">Binary</TD>
	</TR>
	<TR 
ALIGN="LEFT" rowspan="1">
		<TD WIDTH="84" ALIGN="LEFT">CPP, C</TD>
		<TD WIDTH="229" ALIGN="LEFT">C++ source file.</TD>
		<TD ALIGN="LEFT">Text</TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="84" ALIGN="LEFT">PAS</TD>
		<TD WIDTH="229" 
ALIGN="LEFT">Delphi 2.01 source file.</TD>
		<TD ALIGN="LEFT">Text</TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="84" ALIGN="LEFT">H or HPP</TD>
		<TD WIDTH="229" ALIGN="LEFT">C++ header file.</TD>
		<TD ALIGN="LEFT">Text</TD>
	</TR>
	<TR 
ALIGN="LEFT" rowspan="1">
		<TD WIDTH="84" ALIGN="LEFT">DSK</TD>
		<TD WIDTH="229" ALIGN="LEFT">The location of files on the desktop.</TD>
		<TD ALIGN="LEFT">Text</TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">

⌨️ 快捷键说明

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