April 1998
What's new in C++Builder 3
by Kent Reisdorph
C++Builder 3 is out, and it has plenty of new features to tempt you. In this
article, we'll cover some of the most important new features. Many of them are
borrowed from Delphi 3, but some are features that even Delphi doesn't have
yet. (You've probably already noticed that the version following C++Builder 1
is C++Builder 3. Borland did this to synchronize C++Builder's version number
with that of Delphi.)
Project groups
A project group is, not surprisingly, a group of C++Builder projects. When you
open a project group, you have immediate access to all projects in the group.
You can have more than one project open at a time, which is convenient if the
projects interact. The most obvious example is the scenario in which you're
creating a DLL and you have a test application that calls the DLL. With project
groups, you can open both projects at once and switch between them as needed.
A project group also lets you build every project in the group at once, a
serious time saver if you have lots of projects that you need to build on a
regular basis. You'll find many more advantages to project groups once you
begin working with them.
The new Project Manager
The Project Manager is completely new in C++Builder 3. In fact, it's so new
that Delphi doesn't even have it yet! The Project Manager is a tree-view
control that displays the project group at the top and any projects as nodes
under the project group. Within the project nodes are nodes for units, forms,
or support files (RC files or LIB files, for example). You can even add your
own nodes, such as text files or your units' header files.
When you double-click on a form node, C++Builder displays that form in the Form
Designer. If you double-click on a unit node, C++Builder loads that unit and
displays it in the Code Editor.
The Project Manager has the usual features you'd expect, such as the ability to
add files to projects or remove them. We can't discuss all its new capabilities
here, but once you try it, you'll quickly see how great an improvement it is
over C++Builder 1.
C++Builder packages
C++Builder 3 supports packages. A package is essentially just a DLL.
There are two types of packages: design packages and runtime packages. At
design time, the IDE uses design packages, which contain the code to display a
component's icon on the Component Palette and to display the component on a
form at design time. The runtime package contains all the code necessary for a
component to operate at runtime.
Obviously, there's some code overlap in these two packages. In order to
eliminate duplicate code, you usually create a design package so that it uses
code from the runtime package. C++Builder can use packages created for Delphi
3, but you should recompile them using the DCC32.EXE that comes with C++Builder
3.
You can build programs written with C++Builder 3 to use packages or not use
them. If you don't use packages (the default), then your applications will be
just as they were in C++Builder 1. In other words, the code needed for your
application to run is linked into your application's EXE file. If you choose to
use packages, then your application will be much smaller--but you'll have to
ship the runtime packages with your application (which can easily amount to 3MB
or more). If you previously used Borland C++, then you'll recognize this as the
old static linking versus dynamic linking scenario.
New Code Editor features
The Code Editor has some new features that are worth pointing out. I'll also
describe some features that don't pertain directly to the Code Editor, but are
related.
The Code Editor now supports drag-and-drop text editing. To move a block of
text, you select it, then place your mouse pointer over the highlighted text,
click, and drag. The pointer will change to the drag shape, accompanied by a
gray vertical bar. The vertical bar indicates where the text will be placed
when you stop dragging. Once you have the mouse pointer where you want it,
release the mouse button to move the text. To copy text, repeat these steps but
hold down the [Ctrl] key when you release the mouse button. The Code Editor's
drag-and-drop text editing works just like other Windows programs that
implement this feature, so you should feel right at home with it.
Code templates are another nice feature of the Code Editor. Code templates let
you quickly and easily insert prewritten sections of code into your programs.
When you want to insert a code template, you first press [Ctrl]J. A list box
containing the available code templates pops up, as shown in Figure A.
Once you've selected a code template, the text for that template is inserted
into your application at the cursor location. You can then fill in the gaps and
add additional code as needed.
Figure A: This list box contains the available code templates.
C++Builder 3 comes with a number of code templates ready for you to use. For
example, most of the typical C++ language features such as the for loop, the
while loop, the switch statement, and a typical class declaration are
predefined. The great thing about code templates is that you can add your own
to those provided by C++Builder. You add code templates through the Code
Insight page of the Environment Options dialog box or by directly editing the
BCB.DCI file (found in the BIN directory).
Another new feature of the Code Editor is tool-tip expression evaluation. (This
is really a feature of the debugger, but you use it when stepping through code
in the Code Editor.) When your program pauses at a breakpoint, you can place
your mouse pointer over a variable, and a tool tip will appear showing that
variable's value. If you're a Borland C++ 5.0 user, you probably use this
feature frequently. Figure B shows the tool-tip expression evaluator in
action.
Figure B: Tool-tip expression evaluation is a new debugger feature.
The Code Editor now has a visible gutter along the left edge of the editor
window, as you can see in Figure B. This feature makes it much easier to
detect the gutter and avoid it when editing code (I always found myself
inadvertently setting a breakpoint when trying to click on the first column in
the Code Editor). You can change the width of the gutter or hide it altogether.
The gutter contains glyphs that indicate lines for which code is generated, a
breakpoint, or the current execution point.
Find In Files
Finally, GREP has been integrated into the C++Builder IDE! The Find In Files
option allows you to search all open files, all files in the current project,
or files in directories. The results of the search are displayed in the Code
Editor's message window. If you double-click on one of the search listings in
the message window, the corresponding file will open with the line containing
the search text highlighted. This is a great feature and one that many people
have asked for since C++Builder 1 first hit the streets.
Debugger enhancements
The debugger has several new features. One of the best is the tool-tip
expression evaluator we discussed in the previous section. A similar feature
lets you view local variables. When you choose Run | Inspect Local Variables
from the main menu, a Debug Inspector window pops up showing all variables
local to the current function.
Speaking of the Debug Inspector, it's mostly unchanged from the first
version of C++Builder. However, there's one important new IDE feature that
affects the Debug Inspector: The Debugging page of the Environment Options
dialog box contains an Inspectors Stay On Top check box. When this option is
on, all Debug Inspector windows will stay on top of the Code Editor window.
This is a very welcome feature, since most of the time you want your Debug
Inspector windows on top of the Code Editor. The Watch Window also has some
improvements. Most noticeably, when you add a watch, C++Builder immediately
adds to the Watch Window the variable to watch, without first displaying the
Watch Properties dialog box. In C++Builder 1, the Watch Properties dialog box
appears first, forcing you to click OK or press [Enter]. This one-step process
is a welcome improvement.
Another feature of the Watch Window is the ability to set a variable
breakpoint. You can add a variable to the Watch Window and then choose Break
When Changed from the Watch Window speed menu. When that variable changes
value, the debugger will pause program execution as if it had hit a
breakpoint.
The Event Log--another new feature of the IDE and the debugger--replaces and
augments the OutDbg1.txt file from C++Builder 1. It shows status messages for
the modules your program loads, when your program starts and stops, when the
program hits a breakpoint, and other information. To send your own messages to
the Event Log, use the Windows API function OutputDebugString(). You can save
the messages in the Event Log to a file, if you wish.
As I alluded to earlier, the Environment Options dialog box has a new Debugging
page. This page lets you set some new options for the debugger and the Event
Log. More importantly, the page contains settings that determine how exceptions
are handled under the debugger. You'll have to spend some time with the
debugger to really appreciate this feature.
The debugger now lets you start a host application when debugging a DLL.
This is an indispensable feature when you're writing a DLL that will be called
from non-C++Builder applications. To specify a host application, you choose Run
| Parameters from the main menu and type an EXE name in the Host Application
field of the Run Parameters dialog box. When you click the Load button, the
host application will load; you can then debug your DLL as usual. The
C++Builder IDE also has a new utility called the Modules window, which you
invoke by choosing View | Modules from the main menu. This window shows the
modules that are currently loaded and the entry points (functions) of each
module. When you double-click on an entry point, the Code Editor will take you
to the source line containing that entry point (or the CPU view if no source
code exists for the entry point). This is one of those options that is probably
of interest primarily to power users.
Component templates
A component template is a group of components and their associated code that
you save as a unit. Component templates give you quick access to components
that you frequently use in combination with one another. Any templates you've
saved appear on the Templates tab of the Object Inspector. To reuse a component
template, just choose it from the Component Palette and drop it on a form. All
the components in the template will be placed on the form, complete with the
code in any of their event handlers. This feature is very convenient if you use
certain groups of components over and over again.
New components
C++Builder 3 has many new components that you should be sure to check out. I'll
categorize the new components by the Component Palette tab on which they appear.
Additional
TSplitter is a new VCL component. You place it between any two windows you want
to split either horizontally or vertically. If you move the splitter, the
associated windows will resize.
The TCheckListBox component is a scrolling list of check boxes. The TStaticText
component is a label component with its own window handle. This component is
important for applications that depend on a label based on the Windows static
text control.
TChart is a major new native VCL component (unlike the TVtChart ActiveX
control) that makes charting easy. Be sure to look into TChart.
Win32
The Win32 tab was renamed from Win95 and contains several new components. The
TAnimate component encapsulates the Windows animation control and lets you play
AVI videos in a window.
The TDateTimePicker component allows you to choose a date or a time in a
preformatted style. The Kind property determines whether the component
acts as a date picker or a time picker. When operating as a date picker, the
component displays a drop-down calendar you can use to choose a date.
The two most significant components on the Win32 tab are TToolbar and TCoolbar.
The TToolbar component lets you create a toolbar on which all the components
(buttons, combo boxes, and so on) are automatically a uniform height. TCoolbar
is a container component used primarily as a holder for TToolbars. You can
arrange the bands (usually toolbars) on a TCoolbar and size them horizontally
with sizing grips on the left side of the band. The Toolbar and Coolbar
components take some time to figure out, but once you get the hang of how they
work, they're very flexible.
Internet
The Internet tab contains all the Internet components and controls. This tab
includes both VCL components and ActiveX controls. The NetManage ActiveX
controls that shipped with C++Builder 1 have been replaced with new controls
from NetMasters (the company that bought NetManage). The components on this
page are so numerous and varied that we'll just have to say this tab is
definitely worth checking out, and leave it at that.
Database Components
The new database components are primarily designed to make multitier database
programming easier. The TProvider, TClientDataSet, and TRemoteServer components
fall into this category.
TDBChart is another great new database component. It's the data-aware
equivalent of the TChart component we discussed earlier. This component makes
it easy to generate charts from your database data.
The Client/Server version of C++Builder 3 contains an additional tab--Decision
Cube. This tab's six components provide advanced data analysis. The QReport tab
also has some new database-related components you'll want to examine.
Dialogs
The Dialogs tab has two new components, TOpenPictureDialog and
TSavePictureDialog, that are similar to the existing file open and file save
dialog boxes. However, they also provide a preview window for viewing graphics.
Use these components when your application requires users to open BMP, WMF,
EMF, or ICO files.
New language features
C++Builder 3 offers many new language features of which you should be aware.
First, C++Builder now ships with Rogue Wave's Standard C++ Library 2.0. This is
a combination of the classes formerly known as STL and some new classes,
including new templatized IOStream classes. For the most part, your programs
won't know the difference. In some cases, however, the new Standard C++ Library
may require you to modify existing programs.
You'll find a couple of new keywords in C++Builder 3. This version introduces
the __finally keyword, which allows you to use the try/__finally construct. See
the C++Builder documentation for more information.
Another extension allows dynamic functions in classes derived from TObject. A
dynamic function is similar to a virtual function. The difference is that a
dynamic function occupies space in the virtual table only in classes that
define the function. A virtual function occupies space in every derived
class, regardless of whether that class defines the virtual function. Dynamic
functions make for smaller executables--but at the expense of execution
speed--since the virtual tables of all derived classes are searched each time a
dynamic function is called. The __declspec keyword has been expanded to take
the dynamic parameter, as follows:
void __declspec(dynamic) MyFunction();
More project options
If you open the Project Options dialog box in C++Builder 3, you may be shocked
at the number of tabs it contains. There are now three tabs that represent the
basic C++ compiler options: Compiler, Advanced Compiler, and C++. You can leave
most of these options on their default settings. However, power users should
appreciate the availability of these compiler options.
The Linker page has changed somewhat. Perhaps the most significant addition
to the Linker page pertains to DLL projects. The Generate Import Library option
tells C++Builder to create a LIB file for the DLL when the DLL is built. This
means that you no longer have to run IMPLIB from the command line to create a
LIB file for your DLL. The Version Info tab is another addition to the
Project Options dialog box. This page contains everything you need to add
version information to your projects. There's even an option to automatically
increment the build number each time you make the project. The Packages tab
lets you select whether your application will use runtime packages. The TASM
page allows you to set the options that Turbo Assembler uses if your program
contains inline assembly.
You'll notice that C++Builder 3 doesn't provide an option to turn off the
incremental linker (ILINK). ILINK is the linker of choice and is the only
linker available from the IDE. You can still use the old linker, TLINK, from
the command line, but there's really no reason to do so.
ActiveX support
C++Builder now supports creating ActiveX controls using the Active Template
Library (ATL). You can also create active forms, which are entire forms
converted into ActiveX controls.
Database enhancements
In addition to the new database components we listed earlier, C++Builder 3
comes with a new Borland Database Engine (BDE). This version, 4.0, has many new
features, so be sure to check the C++Builder documentation to see what's new.
In general, there's much better support for multitiered database applications.
Another database enhancement is the new SQL Builder application. This tool
replaces the Visual Query Builder and allows you much greater flexibility over
SQL statement creation. The SQL Explorer also has been enhanced.
Finally, shared common files!
This can hardly be considered a hot new feature, but users who keep several
versions of C++Builder and Delphi on the same machine will be glad to know that
Borland has created a new directory containing all the files common to
C++Builder and Delphi. Most notably, the Images directory and the Win32 help
files reside in the common directory. Now you can finally put all those
space-hogging files in one location and share them among your Borland
applications.
Documentation
This version of C++Builder has improved documentation. The book Teach
Yourself C++Builder in 14 Days (written by yours truly) is included in all
versions of C++Builder. This book is a subset of Teach Yourself C++Builder
in 21 Days and is provided in lieu of a user's guide. The Developer's
Guide provides more in-depth coverage of C++Builder and is a natural
companion to the Teach Yourself book. Overall, you should find the new
documentation (printed and online) an improvement over the previous version of
C++Builder.
Conclusion
While this article doesn't cover everything that's new in C++Builder 3, it
gives you a good idea what to expect when you upgrade. In general, C++Builder 3
is a more polished and professional product than C++Builder 1.
Kent Reisdorph is a editor of the C++Builder Developer's Journal
as well as director of systems and services at TurboPower Software Company, and
a member of TeamB, Borland's volunteer online support group. He's the author of Teach
Yourself C++Builder in 21 Days and Teach Yourself C++Builder in 14 Days.
You can contact Kent at editor@bridgespublishing.com.