Home

Introduction to Embarcadero C++Builder

 

C++Builder Fundamentals

 

Introduction

C++Builder offers a practical and easy means of creating computer applications. It uses the C++ computer language as its core syntax and programming logic, adhering to ANSI standards with a lot of improvements on customized items of existing libraries. There are various ways you can launch the program. The most common way consists of clicking.

To create a shortcut on the desktop, in Microsoft Windows higher than Win95, you can click Start -> (All) Programs -> Embarcadero RAD Studio 2010, and right-click C++Builder 2010. You can click Pin To Start Menu to permanently add it to the Start Menu in the same group with Internet Explorer. You can click Send To -> Desktop (Create Shortcut), which would create a C++Builder shortcut on the desktop.

 

Practical LearningPractical Learning: Launching C++Builder

  • To start C++Builder, click Start -> (All) Programs -> Embarcadero RAD Studio 2010 -> C++Builder 2010
     
    IDE
 

Integrated Development Environment

An Integrated Development Environment (IDE) is an application that provides a friendly interface for creating computer programs. C++Builder’s IDE is structurally a classic application. On top, there is a title bar that displays the name of the application and the program currently running. The title bar itself is made of three sections.

C++Builder Projects

 

Project Creation

To create a computer application in C++Builder, you start with a project. A project is a collection of files that, when put together, represent an object that can be executed on various computers (including those that don't have C++Builder). There are different types of applications you can create and thus different ways to start a project.

To create a Windows application, on the main menu, you would click File -> New -> VCL Forms Application - C++Builder:

VCL Form Application

This action starts a project and displays a rectangular object called a form.

Practical LearningPractical Learning: Creating a Project

  • On the main menu, click File -> New -> VCL Forms Application - C++Builder 

Saving a Project

C++Builder allows you to create an "experimental" application that would disappear when you close C++Builder. To use such an experimental application, start by creating a project, do whatever you want with it, including adding other items and resources as we will see throughout our lessons. While using the project, don't save it. If you want to keep everything you have done in a project and continue it another time, you must save the project. Also, if you want to be able to distribute your application to other computers, you must save it.

To save a project, on the main menu, you can click File -> Save All or File -> Save Project As... An alternative is to click the Save All button from the Standard toolbar. When saving a project, you must specify (or create) a folder for the project. You must specify a name for the project and you must name each file used in your application.

Practical Learning Practical Learning: Saving a Project

  1. On the Standard toolbar, click Save All Save All
  2. Type Exercise to replace the name of the Unit1
  3. Click the Create New Folder button
  4. Type Exercise01 and press Enter
  5. Double-click Exercise01 to display it in the Save In combo box
  6. Click Save to save Exercise.cpp
  7. Type Exercise1 to replace the name of the project
  8. Click Save

Program Execution

A program would not mean much unless it accomplishes the desired purpose. To examine how your development is proceeding, you should regularly ask C++Builder to show you the result.

There are three ways you can execute a program in C++Builder. To execute a program:

  • You can press F9
  • You can use the main menu where you would click Run -> Run
  • On the toolbar, you can click the Run button Run

Remember that you can do almost anything without, or before, saving a project. This means that you can execute a project even if it has not been saved already.

Practical LearningPractical Learning: Executing a Program

  • On the Debug toolbar, click the Run button Run

Presenting C++Builder

 

The Classic View

If you had used early versions of C++Builder (<= 6), you may be familiar with its thoughtful style that used independent objects. That is, each window of the programming environment was not connected to the other. Each window could be dragged from one side to another without any effect on the other window. This was an unusual design that presented many options. If you want, you can get that interface.

To get the classic view, on the main menu, click View -> Desktop -> Classic Undocked:

RAD Studio

 

The Title Bar

The title bar is a horizontal bar that signals the application to the operating system:

Title Bar

The title bar displays the system icon System Icon. The system icon is used to identify the application you are using. Almost every application has its own system icon. The system icon holds its own list of actions. For example, it can be used to move, minimize, maximize or close (when double-clicked) a window. These actions are available through a menu that displays when you click the system icon:

System Menu

The main section of the title bar displays Embarcadero RAD Studio 2010. On the right section of the title bar, there are three system buttons with the following roles:

Button Role
Minimizes the window
Maximizes the window
Restores the window
Closes the window
 

The Main Menu

Under the title bar, the main menu displays its various groups of menu items.

In our lessons, the word "Main Menu" refers to the menu on top of the IDE

There are four main types of menu items you will encounter:

  • Menu When clicked, the behavior of a menu that stands alone depends on the actions prior to clicking it. Under the File menu, examples include Save, Close, Close All, or Exit. For example, if you click Close All, C++Builder will find out whether the project had been saved already. If it was, the project would be closed; otherwise, you would be asked whether you want to save it
  • Menu A menu that is disabled is not accessible at the moment. This kind of menu depends on another action or the availability of something else
  • Menu A menu with three dots means an action is required in order to apply its setting(s). Usually, this menu would call a dialog box where the user would have to make a decision.
  • Menu A menu with an arrow holds submenu. To use such a menu, position the mouse on it to display its submenu
Our lessons use the -> arrow for the menu requests. From now on, in our lessons,
Request Means
Edit -> Copy Click Edit then click Copy
View -> Toolbars -> Custom Click View, position the mouse on Toolbars, and then click Custom

If you press F10, the main menu receives focus and a letter becomes underlined on each word of the menu. Examples would be F in File, E in Edit, etc. The underlined letter is called an access key. It allows you to access the same menu item using the keyboard. In order to use an access key, the menu should have focus first. The menu is given focus by pressing either the Alt or the F10 keys.

When the menu has focus and you want to dismiss it, press Esc.

On some menu items, there is a combination of keys we call a shortcut. This key or this combination allows you to perform the same action on that menu using the keyboard.
If the shortcut is made of one key only, you can just press it. If the shortcut is made of two keys, press and hold the first one, while you are holding the first, press the second key once and release the first key. Some shortcuts are a combination of three keys.

The About Box

The About dialog box allows you to get some information about C++Builder and the operating system. To access the About dialog box, on the main menu, you can click Help -> About Embarcadero® C++Builder®. Alternatively, on the right side of the main menu, there is a C++Builder button About. If you click the button, the About dialog box would display:

About

From now on, in our lessons,

Press Means
T Press the T key
Alt, G Press and release Alt. Then press G
Ctrl + H Press and hold Ctrl. While you are still holding Ctrl, press H once. Then release Ctrl
Ctrl + Shift + E Press and hold Ctrl. Then press and hold Shift. Then press E once. Release Ctrl and Shift
 

The Toolbars

A toolbar is an object made of buttons. These buttons provide the same features you would get from the menu. Under the menu, the IDE is equipped with various toolbars. To see the list of available toolbars, you can right-click the one under the main menu:

Toolbars

You can move a toolbar from its default position to another area on the screen. To do this, you can click and drag it away. To position the toolbar back or to somewhere else, you can drag its title bar to the desired location

In our lessons, every toolbar is referred to by its name
 

Toolbar Name Illustration
Standard Standard Toolbar
Debug Debug
Desktop
Browser Browser
View View
Custom Custom

A toolbar is equipped with buttons that could be unpredictable. Just looking at one is not obvious. The solution to knowing what a button is used for is to position the mouse on top of it. A tool tip also called a hint will come up and display for a few seconds:

Tool Tip

The Code Editor

Besides designing applications, one of your most regular jobs will consist of writing code that directs the computer as to what to do, when, and how to do it. This is done in an appropriate window called the Code Editor.

The Code Editor is a feature-rich text editor adapted for coding purposes. It is programmed to recognize the parts of a program that belong to C++ or not. To access the Code Editor, if you have a form opened, you can press F12. The Code Editor manages your jobs by organizing its files into property pages (also called tabs). If your project contains more than one file, you can click the desired tab to access one of the files.

The basic building block of a program is called a C++ file. Whenever you create a new project, the C++Builder programming environment creates a C++ file called Unit1 while the project is called Project1. If you want, you can change these names by saving the project. A typical code of a form is built from at least two files: a header file and a source file. By default, C++Builder does not display this file when a project has been created; you have to request it.

To display the header file of the form, you can right-click the source file and click Open Source/Header File. Indeed, this action is used to toggle both displays. Since the source and the header file go in pair (when using classes), they hold the same name but have different extensions:

The Code Editor

To change the displaying of the form and its code, on the main menu, you can click View -> Toggle Form/Unit. At any time, for example if the programming environment is displaying something other than the form, to display the form, on the main menu, you can click View -> Forms... This would display the list of forms of the application. You can then click the desired form and click OK.

Practical LearningPractical Learning: Exploring the Code Editor

  1. To display the header file, press Ctrl + F6
  2. To toggle between the form and its unit, press F12
  3. To bring back the Code Editor, press F12
  4. Click Exercise.cpp
  5. To bring back the form, press F12
 
 

The Studio Windows

 

The Welcome Page

The Welcome Page is the first wide area that appears when C++Builder comes up. The section displays a title as Recent Projects. At any time, to display the Welcome Page:

  • You can click the Welcome Page button in the middle-upper side of the IDE
  • On the main menu, you can click View -> Welcome Page

If you have just installed C++Builder or have not previously opened a project, the Recent Projects section would be empty. Once you start creating and using projects, they display in the Recent Projects section by their names.

Showing and Closing a Window

When you start or open a project, C++Builder makes some windows available. These are the most regularly used windows. If you think that one of them is not regularly used in your types of assignments, you can remove it from the screen. To hide a window, you can click its Close button Close.

All of the windows you can use are listed in the View menu. Therefore, if a window is not displaying, you can click View on the main menu and click a window of your choice.

Auto Hiding a Window

When creating your applications, you will use a set of windows that each accomplishes a specific purpose. Some windows are represented with an icon but hide the rest of the body. To display such a window, you can position the mouse on it. This would expand the window:

Dockable Windows

If you expand a window, it would display a title bar with two buttons. One is called Auto Hide and the other is the Close button:

Auto Hide

If you expand a window but find out you don't need it any more, you can just move the mouse away from it. The window would return to its previous state. Based on this functionality, if you are working with a window and move the mouse away from it, it would retract. If you need it again, you would have to reopen it using the same technique. If you are going to work with a certain window for a while, you can keep it open even if you move the mouse away. To do this, you can click the Auto Hide button. If clicked, the Auto Hide button changes from pointing left to pointing down:

Auto-Hide

Dockable Windows

By default, C++Builder installs some windows to the left and some others to the right of the screen. You can change this arrangement if you want. To do this, expand a window, then click its title bar and start dragging. To position a window on one side of the screen, drag its title bar to that side. When you get to a side, a transparent blue rectangle would be drawn to indicate the possible position:

Docking

OR

Docking

OR

Docking

You can dock a window only if it is dockable. This means that some windows, such as the Code Editor, are not dockable. To find out whether a certain window is currently docked, right-click its body and notice that the Dockable option is checked:

Dockable

If a window is dockable but you want to prevent yourself from (accidentally) docking it, right-click its body and click Dockable. The check box would be removed from the Dockable option and then, if you drag the window to another location, it cannot be docked.

Floating Windows

Most of the windows you will use are positioned on one side of the screen. If you want, you can have a window that stays on top of other windows but cannot  be "glued" to one side. Such a window is said to float. To float a window, drag its title bar and release it somewhere in the middle of the screen but not on a side because, while dragging, if you release the mouse on one of the sides, and if the window is dockable, it would assume the position of where you released the mouse.

Coupling Windows

You can make two or more windows share one side of the screen or to share an area. To do this, first expand and fix the window that you will use as foundation (or reference). Then, drag the title bar of the window that will share the area:

This

Coupling

Produces

Coupling

Or this

Coupling

Produces

Coupling

Or this

Coupling

Produces

Coupling

 In the same way, you can make two or more windows share the same area.

Help

 

Introduction

There are two main sources of help available for C++Builder. The first source of help is provided with the programming environment. This help is electronic and it is divided in two. Everything considered, this is the closest and the highest documentation that the compiler provides.

Getting General Help

To access the main C++Builder help:

  • On the main menu of RAD Studio, you can click Help -> C++Builder Help
  • On the task bar, you can click Start -> (All) Programs -> Embarcadero RAD Studio 2010 -> RAD Studio Documentation

Practical Learning Practical Learning: Starting Help

  1. On the main menu, click Help -> C++Builder Help
  2. Click the Index tab
  3. In the Look For combo box, type AnsiStr
     
    Help
  4. Notice that the Help environment finds the closest matches
  5. In the list, click AnsiStrComp
  6. Notice the text on the right side of the window
  7. Once again in the Look For text box, type SQL and notice some sub-titles under it
  8. Click Executing commands
  9. Notice the options in the lower-right section of the window
     
    Help
  10. Notice that the main right section of the window displays the details of the item selected
  11. Close the Help window and return to your programming environment

Help on a Word

You can get help on a particular item on the screen. To get this type of help, in the Code Editor, click inside a word and press F1. The Help window would come up and would display information related to that word.

Practical LearningPractical Learning: Getting Contextual Help

  1. Double-click somewhere in the middle of the form
  2. Type TButtonn
  3. Click between B and u
  4. Press F1
     
    Topics
  5. On the left side, click the + button of TButton
  6. Click the + button of Properties
  7. Click Align Property
  8. Close the Help window 

MSDN Help

Because the new RAD Studio shares some features with the Microsoft Developer Network (MSDN), you will need close attention to the MSDN documentation. Fortunately, the RAD Studio ships with, and installs the MSDN documentation. To access it:

  • On the main menu of RAD Studio, you can click Help -> Search
  • If the Help window is already opened, on its Standard toolbar, click Search

Any of these actions would open a Search tab and display a text box. In the Search text box, type the word or expression you want, and click Search or press Enter.

Practical LearningPractical Learning: Accessing the MSDN Help

  1. On the main menu, click Help -> Search
  2. In the text box, type FileStream
  3. Click the Search button
     
    Help
  4. In the list of topics, double-click FileStream Class (System.IO)
     
    Help

Internet Help

Another place you can find information is on the Internet. Fortunately, most of that help is free. On search engine’s web site, you can perform a search on the expression C++Builder (or C++ Builder) and see what you get.

It is very important that you have access to the Microsoft Developer Network documentation. As mentioned above, this help is available from the RAD studio. It is also available free from http://msdn.microsoft.com.

Practical LearningPractical Learning: Exploring Internet Help

  1. In the Help window, on the right side of URL, click the address to select it
  2. Type http://msdn.microsoft.com and press Enter
  3. Close the Help window
  4. To close the RAD studio, on the main menu, click File -> Exit
  5. When asked whether you want to save anything, click No
 
 
 
  
Home Copyright © 2004-2010 FunctionX Next