12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C++</strong> Class Frameworks and the Visual Component Model<br />

When you drop a component on a form, <strong>C++</strong>Builder creates code that <strong>in</strong>herits a class from<br />

the VCL class that represents that component. A po<strong>in</strong>ter to the object is created so that you<br />

can access the objects <strong>in</strong> your code. <strong>C++</strong>Builder uses the Name property <strong>in</strong> the class name and<br />

for the po<strong>in</strong>ter variable’s name. When we created the sample application earlier, we placed<br />

a memo component on the form. At that po<strong>in</strong>t <strong>C++</strong>Builder derived a class from TMemo and<br />

created an <strong>in</strong>stance of that class. Similarly, when we created a button on the form, <strong>C++</strong>Builder<br />

derived a class from TButton and created an <strong>in</strong>stance of that class. Before any of that took<br />

place, <strong>C++</strong>Builder had already derived a class from TForm and, of course, created an <strong>in</strong>stance<br />

of that class to represent the form.<br />

Some understand<strong>in</strong>g of the VCL classes is obviously required to beg<strong>in</strong> work<strong>in</strong>g with VCL.<br />

Although I cannot review each and every class <strong>in</strong> VCL, I can hit the high po<strong>in</strong>ts. Let’s take<br />

a look at some of the classes that you will use most frequently.<br />

Form and Application Classes<br />

Form and application classes represent forms and the Application object <strong>in</strong> VCL. These<br />

classes are all derived from TComponent and <strong>in</strong>deed are components themselves. They are listed<br />

separately to dist<strong>in</strong>guish them from the controls you drop on a form.<br />

TApplication<br />

The TApplication class encapsulates the basic operations of a W<strong>in</strong>dows program. TApplication<br />

takes care of th<strong>in</strong>gs like manag<strong>in</strong>g the application’s icon, provid<strong>in</strong>g context-sensitive help,<br />

and do<strong>in</strong>g basic message handl<strong>in</strong>g. Every <strong>C++</strong>Builder application has a po<strong>in</strong>ter to the<br />

TApplication object called Application. You will use the TApplication class primarily to<br />

execute message boxes, manage context-sensitive help, and set h<strong>in</strong>t text for buttons and status<br />

bars. TApplication is a bit of an oddity <strong>in</strong> VCL <strong>in</strong> that some of its properties (Icon, HelpFile,<br />

and Title) can be set via the Application page of the Project Options dialog box.<br />

TForm<br />

The TForm class encapsulates forms <strong>in</strong> VCL. Forms are used for ma<strong>in</strong> w<strong>in</strong>dows, dialog boxes,<br />

secondary w<strong>in</strong>dows, and just about any other w<strong>in</strong>dow type you can imag<strong>in</strong>e. TForm is a<br />

workhorse class <strong>in</strong> VCL. It has nearly 60 properties, 45 methods, and about 20 events it can<br />

respond to. I am go<strong>in</strong>g to discuss forms <strong>in</strong> detail tomorrow, so I won’t go <strong>in</strong>to a lot of detail<br />

right here.<br />

Component Classes<br />

This group encompasses a wide range of classes. This group could be further broken down<br />

<strong>in</strong>to separate categories, which I’ve done <strong>in</strong> the follow<strong>in</strong>g sections.<br />

157<br />

5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!