Programming with VCL objects

June 11th, 2009 by admin Leave a reply »

Object-oriented programming (OOP) is a natural extension of structured programming. OOP requires that you use good programming practices and makes it very easy for you to do so. The result is clean code that is easy to extend and simple to maintain.

Once you create an object for an application, you and other programmers can then use that same object in other applications. Reusing objects can greatly cut your development time and increase productivity for yourself and others.

This section explains what you need to know about objects to use C++Builder effectively. If you want to create new components and put them on the C++Builder Component palette, see the Creating custom components section of the Developer’s guide.

These are the primary topics discussed in this section:

What is an object?
Inheriting data and code from a class
Object scope
Assigning values to object variables
Creating nonvisual objects

Before reading this section, you should know how to design a user interface for your application using the C++Builder tools, how a C++Builder project is structured, and how to handle events.

What is an object?
An object is an instance of a class that wraps up data and code all into one bundle. Before OOP, code and data were treated as separate elements.

Think of the work involved to assemble a bicycle if you have all the bicycle parts and a list of instructions for the assembly process. This is analogous to writing a Windows program from scratch without using objects. C++Builder gives you a head start on “building your bicycle” because it already gives you many of the “preassembled bicycle parts”–the C++Builder forms and components.

An object is a specific instance of a class. A class is a collection of related information that includes both data and functions (the instructions for working with that data). The properties of C++Builder objects have default values. You can change these values at design time to modify an object to suit the needs of your project without writing code. If you want a property value to change at runtime, you need to write only a very small amount of code.



Leave a Reply