You are on page 1of 10

Borland C++ Compiler

Introduction Borland C++ provides an environment for writing and


running C and C++ programs and for creating DOS and
Windows applications using these languages. The
environment is called an Integrated Development
Environment or IDE.
Starting The IDE To launch the IDE for C++, choose Programming from the
Public menu on the Windows taskbar then choose Borland
C++ from the ++ Compiler option.

The initial screen should appear like this:

Across the top of the window is the title bar with the minimise,
maximise and close buttons on the right-hand side. Under the
title bar are eleven menus.
The File, Edit and Search menus have all the usual Windows
options, whilst the other menus contain options specific to the
C++ environment.
At the bottom of the screen is an information bar that provides
information on the current operation and displays the cursor
position as line and column number.

Borland C++ 1
The Menus The File menu provides commands for creating new files,
opening existing files, saving, printing and exiting the C++
environment.
The Edit menu provides the usual cut, copy, paste and
clipboard commands.
The Search menu allows you to find and replace text and to
search for objects and symbols in the program you are editing.
The View menu allows you to view a number of windows
containing program and environment information.
The Project menu is for the manipulation of project files and
control of all aspects of a project, allowing you to compile all or
part of a program.
The Script menu provides facilities for creating, managing
and running program scripts
The Tool menu allows you to run other programs, tools and
utilities useful in the development of Windows applications,
without leaving the IDE.
The Debug menu provides commands for running and
debugging programs.
The Options menu allows you to edit project and environment
settings and save them to a configuration file.
The Window menu contains window management commands
and selections.
The Help menu gives you access to on-line help including
programming syntax, examples and library information.
Pointing to a menu option and holding down the mouse button
displays a description in the information bar at the bottom of
the screen
The SpeedBar Below the menu bar is the SpeedBar. This consists of a line of
buttons that represent commonly
performed tasks. Initially there
are only 5 buttons for opening and
saving files and projects but more will appear when you start
creating files. The full bar will then look like this:

The extra buttons represent commands to Compile, Link,


Rebuild, Make and Run a program and editor functions such
as Undo, Cut, Copy and Paste. Clicking on a button is faster
than choosing the corresponding command from the menus.
Pointing to a SpeedBar button with the mouse pointer displays
the button label.
SpeedMenus In addition to the main menus, each window opened in the
IDE has its own menu, called a SpeedMenu, displayed by
clicking the right mouse button with the cursor positioned
anywhere in the window.
The options available in the SpeedMenus vary according to the
window being used. The menu for the Edit window looks like
this:

2 Borland C++
To remove the SpeedMenu, click the left mouse button
anywhere outside the menu.
Creating And Programs are best created as part of a project. Projects will be
Running a Program described in more detail later. For now,

choose New from the File menu then select Project to


produce the following Target Expert dialogue window:

This window allows you to set certain properties of the project


you are creating, including its name, and the type of
executable file or ‘target’ you wish to produce.
The settings you set in this window will depend on the
environment in which your program is to run. This is dealt
with in more detail later, but for now, set the Target Type to
EasyWin and leave the other settings unchanged.
You will also need to click on the Advanced button and make
sure the .rc and .def options are unchecked. This will prevent
unnecessary files with these extensions being created.
Click on the Advanced window's OK button to return to the
New Target dialogue box.
You might want to change the name of the project, currently
set to proj0000.ide, and also to add a unique directory
name to the path so that all the files associated with the project
are kept together. The directory will be created automatically if
it does not already exist

Borland C++ 3
Click on the OK button and a new window appears at the
bottom of the screen with a graphical representation of the
project you have just created:

Notice that the project has several levels or nodes, the top is
the executable file with the file extension .exe. Next there is
the source code file with the extension .cpp.
At this stage the executable file and the source file are empty -
they have just been created. You now need to write some code.
Writing The Program Double click on the source filename to produce an empty
Edit window then type in the following simple program
making sure the syntax is correct:

Note that as you type, different C++ constructs appear in


different colours. For example the string, “hello world” is in
blue. Save the program by choosing Save from the File menu.
Compile And Run To compile, link and run the program in one step:

select Run from the Debug menu or click on the Run


button in the Speed bar. You can also double click on the
executable file name in the Project window.

A window titled
Compile Status
appears over the Edit
window informing
you of the progress of
the compilation and
linking sequence.
If the compilation is
successful, the
program will run
automatically in an
output window with
the name of the
program at the top.

4 Borland C++
The program prints the words “hello world”:

To switch back to the Edit window, use the Window menu or


click anywhere in the window itself. To close the output
window, click on the close button in the window’s top
right corner.
Compiler Errors If the compilation is not successful, the Status window will
say there are errors. Clicking on OK will then display error
messages in the Message window at the bottom of the screen.
Highlighting an error with a single click will move the cursor
in the Edit window to the offending line in the program. You
can switch between the Edit and Message windows using the
Window menu or by pointing anywhere in the required
window.
After correcting any mistakes, choose Run from the Debug
menu again to recompile and run the program.
Closing And When you have finished working on a project, choose ‘Close
Opening Projects project’ from the Project menu. If you have any unsaved
changes, you will be prompted to save them.
To start another project, choose ‘New project’ from the Project
menu or to open an existing project, choose ‘Open project’ and
select the required project file.
If you have finished working, quit Borland C++ by choosing
Quit from the File menu.
Projects And The A Project is a collection of files dependent on each other. Some
Project Manager of the files will contain source code created by the user, whilst
others will be object files, executable files and library files
created by the compiler, linker or other tools.
The project manager provides a powerful facility to control
compilation and linking operations and to keep track of all the
files, their interdependencies and their compiler options by
use of a project file which is consulted whenever a new
compilation occurs.
This system is most useful when changes are to be made only
to some of the files in the project. The project manager can
then be used to recompile only those files that have been
modified and will automatically update any dependent files.
When you create a project, there are various properties that
need to be set to achieve the desired executable code. The basic
options are set in the New Project window mentioned earlier,

Borland C++ 5
in which you accepted the default settings for the example
program. The options are described more fully here.
Filenames The names of most generated files in a project are derived
from the name given to the project file, though they will have
different extensions.
The general convention for filenames is:
Project file .ide
Executable file .exe
Source file .cpp or .c

Target Types In addition to .exe files, the target may be a static library file
with an extension of .lib, a dynamic link library with an
extension of .dll or a Windows help file with an extension of
.hlp.
The setting used for Target Type will determine the range of
platforms that can be chosen for the program. Choosing
Application gives a choice of all types of platform (DOS, 16-bit
Windows and 32-bit Windows), whilst selecting EasyWin only
offers 16-bit Windows as a platform.
Target Platforms You should choose a target platform according to the system
on which you intend to run your program. Options include 16-
bit Windows, 32-bitWindows or standard 16-bit DOS
applications with or without overlays.
Target Models The target model refers to the memory model to be used. Small
is sufficient for many programs. If you find that you have
memory problems when compiling or running the program,
you can change the memory model to make use of more
memory. Models change depending on the target type.
The Project Tree The project tree will always show all the files associated with
the open project. A node containing a + sign indicates that it is
dependent on other files. These can be viewed by clicking on
the + sign. When this is done, the dependent files are revealed
and the + changes to a – sign.
Under the source node of the project tree you might see several
files that were added to the project when it was compiled by the
project manager. The full tree may look something like this:

Compiling A Project In the previous example project, the act of compilation,


linking and running was performed in one step by selecting
Run from the Debug menu.
In more complex projects, you will often need to compile or
link files without running them and there are several ways in
which this can be done.
Building Compiling and linking code in a project is called building the
project. To build the whole project, choose ‘Build all’ from the
Project menu. This will recompile and link all source code in
the project.

6 Borland C++
Making If you have previously built a project and have made changes
to parts of it, choosing ‘Make all’ from the Project menu will
rebuild only those files containing changes since the last build
plus any files dependent on them.
It is also possible to build or make individual nodes of a project
tree. To do this, select the node of the tree by right clicking on
it, then, from the SpeedMenu, choose either ‘Build node’ or
‘Make node’.
Editing A The project tree can be edited by adding or deleting files or
Project Tree nodes, changing node and target
attributes or moving targets and nodes.
To change a node in the project tree, make
the Project window active and right-click
on the node to reveal the SpeedMenu then
choose the required option.
The options available will vary depending
on the type of node selected.
Copying Project To copy nodes from one part of a project to
Nodes another or to another project, select the
node to be copied, hold down the CTRL key
and drag the selected node to the required position in the
project tree. All the dependants of the node are automatically
copied.
Setting Project Once you have created a project, you may need to change the
Options default build options. These options tell the project manager
how to build the project (for example, they specify whether
debugging information is to be included or if optimisation is to
be performed). Project options are used to build the entire
project and are also passed on to any new projects you create.
To change project options, choose Project from the Options
menu to produce the following dialogue box:

The options are listed on the left. Those with a + next to them
contain further options that can be viewed by clicking on the +
sign. This will also reveal a brief explanation of the option
highlighted.
Further clicking on a sub-heading enables the options to be
changed by entering text in or by checking or unchecking the
appropriate box.

Borland C++ 7
Style Sheets The options set for a project form a Style Sheet. The settings in
a Style Sheet determine how the project is built. If all the
components in a project can be compiled with the same
options, these can be set in the Project section of the Options
menu.
However, if you want to build different nodes in the project
with different options, you can set a Style Sheet for that node or
use local override as detailed below.
When the project manager builds a node, it refers to the node’s
Style Sheet and any local override options. If the node does not
have a Style Sheet of its own, the project manager uses the
Style Sheet of the node’s parent.
If the parent node does not use a Style Sheet, the manager
looks at the next parent, continuing until it uses the project’s
Style Sheet.
Overriding Project Sometimes you might need to use different options to the
Options default for a particular file or node so you will want to override
the project options locally.
To do this:
Right-click on the node whose options are to be overridden.
Choose ‘Edit local options’ from the SpeedMenu. This
produces the Style Sheet dialogue box containing the node’s
options.
Select the option you wish to override and the Local
Override box is checked automatically.
Click OK to complete the procedure.

Saving Options Any changes you make to the project options will be effective
for the current session, including new projects. By default, the
settings are also automatically saved in a configuration file for
future sessions.
Debugging Programs No matter how careful you are when you write your code, your
program is likely to contain bugs or errors that prevent it from
running. There are three basic types of error: compile-time
errors, run-time errors and logic errors.
Compiler errors are due to incorrect syntax in your program
and will be shown in the Message window at compile time.
Run-time errors are due to statements not being executed or
giving an inappropriate result for some reason such as an
attempt to open a non-existent file or to divide by zero. These
will cause an error message to appear on execution.
Logic errors are errors in design and implementation such
that, although the program works, it may not be doing what
you intended. To track down these errors use the debugging
facility of the IDE.
Running The To use the debugger you must first compile and link the
Debugger program with debugging options on. This is, in fact, the
default setting but to make sure, choose Project from the
Options menu then select Compiler/Debugging to see that the
option 'Generate debug information' is checked in the
dialogue box.
The debugger allows you to step through the program one
statement at a time allowing you to examine the state of the
program and check the values of variables.

8 Borland C++
Stepping To step through the code choose Step into from the Edit
Through Code windows SpeedMenu or click on the Step into button in the
SpeedBar. To follow the code in called functions, use Step over
instead
To run the program to a specific location, position the cursor
at the line where you want the program to halt, then choose
Run to current from the SpeedMenu or the Run to here button
in the SpeedBar.
Setting Breakpoints A breakpoint is a designated position in the code where you
want the program to stop executing and return control to the
debugger. This is similar to using Run to current except that
there may be multiple breakpoints in a program.
To set a breakpoint, move the cursor to the required line of
code in the Edit window then choose Toggle breakpoint from
the Debug menu or the window’s SpeedMenu.
Now, when the program runs, it will stop at the breakpoint
before executing the code. Note that the code at a breakpoint
must be executable
To delete breakpoints, move the cursor to the line and choose
‘Toggle breakpoint’ again.
Examining And To see the current values of variables or expressions choose
Changing Values Watch from the View menu. This will open the Watch window
that is initially empty. Choose Add watch from the Debug
menu and type in the name of the variable or the expression
you wish to view.
You can also modify the values of variables by using the
Expression Evaluator dialogue box. To use this, choose Modify
from the Evaluate option of the Debug menu. Enter the
variable in the expression box then type the new value in the
New Value box. To make the new value take effect choose
Modify, otherwise the debugger will ignore the new value.
Stopping There are two ways of stopping the program executing; these
The Program are Pause process and Terminate process, both of which can
be chosen from the Debug menu. When using Pause process,
you can resume execution from the same point by choosing
Run from the Debug menu.
If you choose Terminate process, all subsequent running,
stepping or tracing will begin at the start of the main
program.
Browsing Code The Browser allows you to view the objects, functions, classes,
variables, types and constants used by your program. To use
the Browser, the program must be compiled with certain
options set in the Project Options dialogue box. To do this,
choose Project from the Options menu, then choose
Compiler/debugging from the topics available.
As well as the debug options previously mentioned, you should
make sure that the option ‘Browser reference information in
OBJs’ in the Compiler/Debugging section is checked.
To see an overview of all objects in your program choose
Classes from the View menu. This will produce a hierarchy of
dependent relationships.

Borland C++ 9
To see a list of all the symbols in the program choose Globals
from the View menu. This produces the following window:

The nature of the symbol is indicated by the letter alongside its


name, F for function, T for type, C for constant, V for variable,
I for inherited and a lower case v meaning virtual method. A
question mark indicates that the symbol is debuggable.
You can select which types of symbol are displayed by using
the Filters section of the window. Clicking the top or bottom
row of the filter moves a letter up or down. A letter in the top
row means that the browser will display symbols with that
identification. A letter in the bottom row means that the
browser excludes those symbols.
To obtain more information on a particular symbol or object,
double click on the symbol name in the Browser window.
The Browser can also be started by choosing Browse Symbol
from the Search menu or by placing the cursor on a symbol in
the code and choosing Browse Symbol from the Search menu.
Leaving The IDE To leave the C++ Integrated Development Environment choose
Exit from the File menu.
Creating Windows Although Borland C++ has extensive facilities for creating full
Applications Windows programs with graphical user interface (GUI),
these aspects are not covered in this chapter. The Application
Expert (AppExpert) under the Project menu can be used to
create a basic application but users are referred to the relevant
manuals or to the on-line help system for assistance in this
area.

10 Borland C++

You might also like