[an error occurred while processing this directive]



2. The first form

Starting the Borland C++ Builder, a new project is created. To set its name we can select the Save all option from the File menù. First of all we'll be asked to write the name we want to use for the basic form's code and the resource files. Writing BasicUnit, C++ Builder will create the files:

BasicUnit.h
BasicUnit.cpp
BasicUnit.dfm

Note
If you have already used C++, the first two files will probably sound familiar to you: they are respectively the header file (.h), where class declaration are saved and the file containig the class's code (.cpp). The third file contains form's resources which consist in its visual layout and something more.

Then we'll be asked to chose a name for the project we are working to. Call it Archive. C++ Builder creates the following files:

Archive.mak
Archive.res

Project's WorkSpace is now ready. C++ Builder's WorkSpace is the programming enviroment and it's made up by three parts: at the top there is a bar (fig.2.1) containing a menù which holds the visual components (VCL) that developers can use to build their applications. Components are divided, according to thier functionality in Standard, Win95, Additional, Data Access, Data Control, ... . It is possible to make the desidered menù visible by clicking on the corresponding flap. In the same bar there are some buttons whose functions will be explained time by time we'll use them and the classic File, Edit, Search, View, Project, ... menù.





fig.2.1: Some Borland C++ Builder's VCL components



Under this bar are applications' forms. The forms are the windows our project will show at execution time. In the same position is C++ Builder's text editor we'll use to write classes' code (fig.2.2).





fig.2.2: An empty new form.



In the forms it is possible to insert components got from the components' menù. Each component, form included, is characterized by a large number of properties, methods and events they generate. On the left side is a window called Object Inspector (fig.2.3) through which selected components' properties and events can be visualized and edited. Acting on the Object Inspector we can set components' properties and handle a particular function to one or more events.





fig.2.3: C++ Builder Object Inspector



That's the WorkSpace. Now we can begin building Archive's basic form. To set form's name select the form named Form1 (this is the name C++ Builder gives to the form by default) in the Object Inspector's menù (fig.2.4), search the Name property (fig.2.5) and substitute the text Form1 with BasicForm. To change the text shown on window's title bar we have to act on the Caption (fig.2.6) property. Set its value to Archive.





fig.2.4: Object Inspector. Object selecting




fig.2.5: Object Inspector. Name property




fig.2.6: Object Inspector. Caption property



To understand better what we are doing, it is possible to ask to C++ Builder to compile, link and execute the application. Select the Run option in the Run menù or press F9. Some seconds after our programm will be ready and executed. Actually it consists in an empty window named Archive. Not much, but it's already a full-working application. To stop Archive's execution press the crossed button at the top right of the window or use the Program Reset function in the Run menù. We are back to the workspace. Now we'll add some buttons to the window and write the function to call when the buttons are clicked. C++ Builder has different kind of buttons. We'll use the TBitBtn buttons which can be found in the Additional menù (fig.2.7).





fig.2.7: Visual component Additional menù



A BitBtn Button allows us to insert an icon near the text shown on the button. Clicking on the figure representing the BitBtn component in the Additional menù and then on the BasicForm the new button will be added to the form. Now it is possible to set component's dimensions and position by dragging its corners. Select the button in the form and press F11 to have the object shown in the Object Inspector. We have to be sure the object's properties shown are the button's ones. Look at the menù at the top of the Object Inspector window, we should read BitBtn1:TbitBtn, which are the name and type of the object we are working on. Editing the Caption property we'll change the text on the button. To choose the icon you want to have on the button you can use the Glyph property. Through this property it is possible to load an image from a .ico file. Some default icons are collected in the "../Borland/Cbuilder/Images/Buttons" directory. Select the icon you prefer and set button's text on Exit (Caption property). The resulting window is shown in fig.2.8.




fig.2.8: Archive's BasicForm



To handle a function to the event "button pressed" click on the Events' flap in the Object Inspector window and double click on the white space on the right of the OnClick event (be sure the events we are working on are button's ones). C++ Builder positions the cursor in the code editor window and creates an empty function called BitBtn1Click() in the unit we called BasicUnit. What we have to do now is completing the function connected to the button's event OnClick by writing its body. Add these lines: BasicForm->Visible=false;
exit(1);
In this way, the function executed when the button is pressed will be: void __fastcall TBasicForm::BitBtn1Click(TObject *Sender)
{ BasicForm->Visible=false;
exit(1);
}

We have now a button that hides the basic window working on the form's Visible property (BasicForm->Visible=false) and then ends the program's execution exiting with exit code "1" (exit(1)). It's time to compile the application pressing F9 and test its correct working.

If everything works correctly you can read the following chapter in wich we'll build a new form to display/edit/add data in Persons.DB table.





Italia HyperBanner Network