Borland C++ Compiler. Introduction

Similar documents
BIGPOND ONLINE STORAGE USER GUIDE Issue August 2005

Introduction to the use of the environment of Microsoft Visual Studio 2008

3 IDE (Integrated Development Environment)

Company Setup 401k Tab

Introduction To Microsoft Office PowerPoint Bob Booth July 2008 AP-PPT5

CNC Transfer. Operating Manual

How to test and debug an ASP.NET application

Hypercosm. Studio.

How to Concatenate Cells in Microsoft Access

Creating tables in Microsoft Access 2007

Introduction to MS WINDOWS XP

Installing and using XAMPP with NetBeans PHP

Using the Query Analyzer

Bitrix Site Manager 4.0. Quick Start Guide to Newsletters and Subscriptions

Adobe Digital Signatures in Adobe Acrobat X Pro

Internet Explorer 7. Getting Started The Internet Explorer Window. Tabs NEW! Working with the Tab Row. Microsoft QUICK Source

ECDL. European Computer Driving Licence. Spreadsheet Software BCS ITQ Level 2. Syllabus Version 5.0

Getting Started with the Cadence Software

Windows XP Pro: Basics 1

Programming with the Dev C++ IDE

DataPA OpenAnalytics End User Training

Microsoft Access 2010 Overview of Basics

Content Author's Reference and Cookbook

For Introduction to Java Programming, 5E By Y. Daniel Liang

Utilities ComCash

Introduction to Word 2007

Avaya Network Configuration Manager User Guide

During the process of creating ColorSwitch, you will learn how to do these tasks:

Business Objects Version 5 : Introduction

Debugging Java Applications

Microsoft Word Quick Reference Guide. Union Institute & University

Code::Block manual. for CS101x course. Department of Computer Science and Engineering Indian Institute of Technology - Bombay Mumbai

Code::Blocks Student Manual

Appendix K Introduction to Microsoft Visual C++ 6.0

Compute Cluster Server Lab 3: Debugging the parallel MPI programs in Microsoft Visual Studio 2005

UOFL SHAREPOINT ADMINISTRATORS GUIDE

Using Example Projects, Code and Scripts to Jump-Start Customers With Code Composer Studio 2.0

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

Creating forms in Microsoft Access 2007

1.5 MONITOR. Schools Accountancy Team INTRODUCTION

The VB development environment

Bitrix Site Manager 4.1. User Guide

Excel 2007: Basics Learning Guide

Introduction to Simulink

Unleashing Hidden Powers of Inventor with the API Part 1. Getting Started with Inventor VBA Hello Inventor!

Creating a Simple Visual C++ Program

Data Tool Platform SQL Development Tools

COINS User Guide: Human Resources Training Manual

WORDPAD TUTORIAL WINDOWS 7

Using Excel for Business Analysis: A Guide to Financial Modelling Fundamentals

Excel 2003 A Beginners Guide

Create!form Folder Monitor. Technical Note April 1, 2008

Job Scheduler User Guide IGSS Version 11.0

DsPIC HOW-TO GUIDE Creating & Debugging a Project in MPLAB

Using Process Monitor

IT Quick Reference Guides Using Windows 7

Umbraco v4 Editors Manual

Test Generator. Creating Tests

Merging Labels, Letters, and Envelopes Word 2013

Migrating to Excel 2010 from Excel Excel - Microsoft Office 1 of 1

1 Introduction. 2 Project Browser. 3 FlowStone Editor

EXCEL PIVOT TABLE David Geffen School of Medicine, UCLA Dean s Office Oct 2002

Xcode Project Management Guide. (Legacy)

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Using Microsoft Project 2000

JAWS 6 and Internet Explorer 6.0

How do you use word processing software (MS Word)?

FrenzelSoft Stock Ticker

Exclaimer Mail Archiver User Manual

USER MANUAL (PRO-CURO LITE, PRO & ENT) [SUPPLIED FOR VERSION 3]

Vodafone PC SMS (Software version 4.7.1) User Manual

Simply Accounting Intelligence Tips and Tricks Booklet Vol. 1

State of Illinois Web Content Management (WCM) Guide For SharePoint 2010 Content Editors. 11/6/2014 State of Illinois Bill Seagle

Creating Cost Recovery Layouts

Welcome to The Grid 2

Attix5 Pro. Your guide to protecting data with Attix5 Pro Desktop & Laptop Edition. V6.0 User Manual for Mac OS X

Microsoft Excel Introduction to Microsoft Excel 2007

1.5 MONITOR FOR FMS 6 USER GUIDE

Statgraphics Getting started


Guidelines for Accessing and Using the VDOT Scheduling Application (Primavera P6)

Attix5 Pro Server Edition

Analyzing Excel Data Using Pivot Tables

Logi Ad Hoc Reporting System Administration Guide

ACCESS 2007 BASICS. Best Practices in MS Access. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

AFN-FixedAssets

Doña Ana County, NM Map Help

Generative Drafting. Page DASSAULT SYSTEMES. IBM Product Lifecycle Management Solutions / Dassault Systemes

Computer Training Centre University College Cork. Excel 2013 Level 1

The following is an overview of lessons included in the tutorial.

Introduction to Microsoft Access 2003

Smart Connection 9 Element Labels

Handout: Word 2010 Tips and Shortcuts

Navios Quick Reference

Personal Call Manager User Guide. BCM Business Communications Manager

DiskPulse DISK CHANGE MONITOR

Excel 2007 Basic knowledge

Viewing and Troubleshooting Perfmon Logs

Quick Guide. Passports in Microsoft PowerPoint. Getting Started with PowerPoint. Locating the PowerPoint Folder (PC) Locating PowerPoint (Mac)

Desktop, Web and Mobile Testing Tutorials

Transcription:

Borland C++ Compiler Introduction Starting The IDE 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. 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 SpeedBar 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 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: SpeedMenus 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. 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++

Creating And Running a Program To remove the SpeedMenu, click the left mouse button anywhere outside the menu. Programs are best created as part of a project. Projects will be 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: Writing The Program 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. 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: Compile And Run 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. 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 : Compiler Errors Closing And Opening Projects Projects And The Project Manager 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. 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. When you have finished working on a project, choose Close 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. A Project is a collection of files dependent on each other. Some 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

Filenames Target Types Target Platforms Target Models The Project Tree in which you accepted the default settings for the example program. The options are described more fully here. 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 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. 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. 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 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 Building 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. 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 Editing A Project Tree Copying Project Nodes Setting Project Options 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. The project tree can be edited by adding or deleting files or 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. To copy nodes from one part of a project to 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. Once you have created a project, you may need to change the 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 Overriding Project Options Saving Options Debugging Programs Running The Debugger 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. Sometimes you might need to use different options to the 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. 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. 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. To use the debugger you must first compile and link the 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 Through Code Setting Breakpoints Examining And Changing Values Stopping The Program Browsing Code To step through the code choose Step into from the Edit 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. 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. To see the current values of variables or expressions choose 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. There are two ways of stopping the program executing; these 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. 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: Leaving The IDE Creating Windows Applications 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. To leave the C++ Integrated Development Environment choose Exit from the File menu. Although Borland C++ has extensive facilities for creating full 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++