Inheriting data and code from a class

The TForm1 class might seem quite simple. If you create the application, TForm1 appears to contain one data member, Button1, one method, Button1Click, and no properties. Yet you can change the size of the form, add or delete Minimize and Maximize buttons, or set up the form to become part of a Multiple Document Interface (MDI) application. How is it possible to do all these things with a form that contains only one data member and one method?

The answer lies in the notion of inheritance. Recalling the bicycle analogy, once you have put together all the objects that make up a complete "bicycle object," you can ride it because it has all the essentials to make the bicycle useful--it has pedals you push to make the wheels go around, it has a seat for you to sit on, it has handlebars so you can steer, and so on. Similarly, when you add a new form to your project, it has all the capabilities of any form. For example, all forms provide a space to put other components on them, all forms have the methods to open, show, and hide themselves, and so on.

Suppose, though, that you want to customize that bicycle, just as you would customize a form object in C++Builder. You might adjust a few gear settings, add a headlight, and provide a horn with a selection of sounds--just as you might customize a form by adding or rearranging buttons, changing a few property values, and adding a new method that allows the form to appear with a plaid background.

To change the bicycle to make it exactly as you want it, you start with the basic model and then customize it. You do the same thing with C++Builder forms. When you add a new form to your project, you've added the "basic model" form. By adding components to the form, changing property values, and writing event handlers, you are customizing the new form

About the Author:

MoreHere

Article Source: ArticlesBase.com - Inheriting data and code from a class

object-oriented programming (oop), c, c++, c++builder, custom components, developer’s guide, object scope, easy, swift programming, how to swift easy, learn to easy program