Department of Information Engineering INFORMATION TECHNOLOGY dr Lszl

  • Slides: 13
Download presentation
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /0. l C++ programming

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /0. l C++ programming in Windows environment The Borland C++ Builder l Building elements of the program: the components l The Visual Component Library (VCL) l Structure of VCL l Application models handling single, or multiple documents (SDI, MDI) l Project handling of C++ Builder l The first steps of making an application

Department of Information Engineering INFORMATION TECHNOLOGY l Building elements of the program: the components

Department of Information Engineering INFORMATION TECHNOLOGY l Building elements of the program: the components The component is such an object (e. g. a button) that works already during planning, writing the program, consequently the values of its properties can be set without writing program code. From a lot of pre-programmed components realising given task the exactly required instance can be selected for the program. The components can easily be put on the form of designed window selecting them from the componentpalette. dr. László Dudás 10. /1.

Department of Information Engineering INFORMATION TECHNOLOGY The event is an occurrence, e. g. a

Department of Information Engineering INFORMATION TECHNOLOGY The event is an occurrence, e. g. a button click by mouse, that comes from the user interaction or the Windows operating system. The list of events that can happen on a selected component (e. g. button) is given in the Events page of the Object Inspector. The handling of an event is performed by the event handler function of the component. The event handler is that among the member functions of the component affected by the event which starts to run because of the event and answers it (e. g. closes the window). The skeleton of the event handler function can be created in the program double clicking on the name of the selected event in the Events page. The internal code of the function that answers to the occurrence has to be written by us. dr. László Dudás 10. /2.

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /3. The answering code

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /3. The answering code has to be entered here by you! Double click on the name of the event and the skeleton of the event handler is ready.

Department of Information Engineering INFORMATION TECHNOLOGY The components have non event handler member functions

Department of Information Engineering INFORMATION TECHNOLOGY The components have non event handler member functions too, these functions are the methods. The methods can be called by us too in the code segment written by us. Among the methods there are the constructor and the destructor. E. g. the calling of the Focused() method answers the question is the control component in focus, so it is selected for getting the effects originate from the user actions. In the working program the control which is in the focus is set off using framing, colouring or another method. In case of Properties, Events and Methods the Help informs us about the ancestor class where these characteristics were defined the first time, where they are inherited to the class of the object from. dr. László Dudás 10. /4.

Department of Information Engineering INFORMATION TECHNOLOGY The Help gives detailed information about properties of

Department of Information Engineering INFORMATION TECHNOLOGY The Help gives detailed information about properties of every single class. Because of its complexity the C++ Builder is practically not usable without the online Help. Program examples support the understanding and applying of components. A tutorial is included for beginners in the Help/C++ Builder Help/Contents/ Quick Start: Tutorials point. Example programs that introduce the possibilities of C++ Builder are in the Examples folder. dr. László Dudás 10. /5.

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /6. l The Visual

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /6. l The Visual Component Library (VCL) As C++ Builder is suitable for writing programs that run on Windows graphical operating system and use the resources of Windows API, it is evident that includes a graphical object library which uses and simultaneously hides the API. The visual attribute means that these objects mostly displayed on the screen: window-forms, menus, input panels, controls, etc. For non visual objects an example is the timer. VCL classes are organised into a class hierarchy. The C++ Builder borrowed this structure from the Borland Delphi program development environment, that uses the Object Pascal programming language. The VCL provides the components to a quick build-up of Windows-style user interface but the internal program code that gives the essence of the application has to be entered using C++ language. The capabilities of Object Pascal based VCL have the next differences compared to possibilities of C++: l The VCL objects have to be created dynamically (new, delete) l The member functions of VCL objects have not default parameter values l The VCL objects cannot have multiple ancestors.

INFORMATION TECHNOLOGY Department of Information Engineering dr. László Dudás 10. /7. l Structure of

INFORMATION TECHNOLOGY Department of Information Engineering dr. László Dudás 10. /7. l Structure of VCL (detail) TObject TStream TGraphic TMenu TPersistent TComponent TControl TShape TApplication TWin. Control TGraphic. Control TImage TStrings TScrolling. Win. Control TCustom. Form TCustom. Control TButton

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /8. TObject is the

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /8. TObject is the ancestor of VCL classes. The descendants of TPersistent class can save and load their features to/from files. TComponent is the ancestor of components. Their descendants have properties and methods that make possible to install them into the Component Palette and to add them to forms. TControl is the ancestor class of controls appearing in the user interface. The instances of TApplication class are the applications. It has methods like Initialize(); Create. Form(); Run(); for control of the application and to handle the message transmitting cycle. They are called in Win. Main() function. TForm is class of windows, the main window of the application, the dialog windows of the user interface are derived from it. The structure, the parts of the built window are included in the. DFM file, the program code regarding its work is in the. CPP file and the declarations are given in the. H header file. The programmer don’t have to deal with the. DFM file, its creation is automatic. Custom classes can constitute the basis class of classes built further from them by the programmer. These new classes are not given in the class hierarchy originally.

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /9. l Application models

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /9. l Application models handling single, or multiple documents (SDI, MDI) The applications can be of two sorts: The SDI, Single Document Interface program can use countless further dialog and message windows over the main window, but can work on one document only. The MDI, Multiple Document Interface program can run countless further document windows in the main window that have the same structure and can display different documents. The menus and icons in the main window refers to the active document. E. g. remember the Windows/Tile function of Excel. The application model of the main window of our application can be selected by the Form. Style property of its form. The document windows of an MDI application are non modal windows: more than one can be opened at the same time, every can be selected clicking in it and can be used for work. Such windows have to be displayed calling their Show() method. Modal windows have to be closed before clicking effectively in another window of the application. Such windows applied in every application model: most of the dialog windows are such. This behaviour is caused by the Show. Modal() method.

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /10. l Project handling

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /10. l Project handling of C++ Builder The C++ Builder development environment administers the files created during developing process hidden in the project file (e. g. football. bpr). The starting file including the Win. Main() function is made automatically. (e. g. FOOTBALL. cpp).

Department of Information Engineering INFORMATION TECHNOLOGY The units consist of a. cpp and a.

Department of Information Engineering INFORMATION TECHNOLOGY The units consist of a. cpp and a. h pair of files. In case of forms this pair is completed with a. dfm form-definition file that is made automatically. The Project Manager does not show the. h header files. The. resource file and other, rare used files (. txt, . bmp, . wav) can be attached to the above mentioned files. dr. László Dudás 10. /11.

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /12. l The first

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10. /12. l The first steps of making an application 1. Create a new folder which will store the files of the project. 2. Start C++ Builder. 3. If a previous project were open choose the File/Close all menu item and close it. Then create a new project with the File/New Application menu point. The C++ Builder creates the next files automatically: Project 1. cpp : the main program Unit 1. cpp : the source code file for the main form that is named unit file Unit 1. h : the header file for the main form that is named unit header file Unit 1. dfm : resource file that describes the structure of the main form. 4. Choose the File/Save All menu item and save the files to the previously created folder. Rename the. bpr project file to taste during saving. The default names of units can be kept or renamed at will. 5. Later the full project has to be saved by the File/Save All menu item. This is expedient after every bigger modification.