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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

In addition to the GDI classes listed here, there are others that either work as helper classes<br />

or extend a base class to provide extra functionality. As you work with <strong>C++</strong>Builder you will<br />

learn more about these classes and how to use them. Figure 5.6 shows the hierarchy of the<br />

VCL classes that encapsulate GDI operations.<br />

Figure 5.6.<br />

VCL GDI class<br />

hierarchy.<br />

TPicture<br />

TObject<br />

TPersistent<br />

TGraphic TCanvas<br />

TGraphicsObject<br />

TBitmap TIcon TMetaFile TMetaFileCanvas TControlCanvas TBrush TFont TPen<br />

Utility Classes<br />

So far I have discussed component classes. VCL also conta<strong>in</strong>s utility classes you can use <strong>in</strong><br />

your applications. A utility class simplifies some tasks <strong>in</strong> W<strong>in</strong>dows programm<strong>in</strong>g. For<br />

<strong>in</strong>stance, the TIniFile class eases the use of writ<strong>in</strong>g and read<strong>in</strong>g W<strong>in</strong>dows configuration files<br />

(.INI files). Conventional wisdom has it that the use of .INI files is out and the Registry is<br />

<strong>in</strong>. To aid <strong>in</strong> Registry operations, VCL has the TRegistry and TRegkeyInfo classes.<br />

The TRect and TPo<strong>in</strong>t classes (which are really just structures) aid <strong>in</strong> us<strong>in</strong>g various VCL and<br />

W<strong>in</strong>dows functions requir<strong>in</strong>g a po<strong>in</strong>t or rectangle parameter.<br />

The TStr<strong>in</strong>gs class is used to manipulate str<strong>in</strong>gs, and the TStr<strong>in</strong>gList class allows for arrays<br />

of str<strong>in</strong>gs. These classes are used by many of the component classes to store str<strong>in</strong>gs. For<br />

<strong>in</strong>stance, the TMemo class uses a TStr<strong>in</strong>gList object for its L<strong>in</strong>es property. TStr<strong>in</strong>gList has the<br />

capability to save its list of str<strong>in</strong>gs to file or load str<strong>in</strong>gs from a file us<strong>in</strong>g the LoadFromFile()<br />

and SaveToFile() methods.<br />

And That’s Not All…<br />

By no means did I cover all of the VCL classes here. I did, however, touch on the classes that<br />

you are most likely to use <strong>in</strong> your applications.<br />

Flip back a few pages and take another look at List<strong>in</strong>g 5.1 and the OWL example that<br />

performs the equivalent code <strong>in</strong> List<strong>in</strong>g 5.2. If you recall, I said that plac<strong>in</strong>g a bitmap image<br />

on a w<strong>in</strong>dow is even easier <strong>in</strong> <strong>C++</strong>Builder. Let me show you what I mean. First, beg<strong>in</strong> a new<br />

application <strong>in</strong> <strong>C++</strong>Builder. You should be look<strong>in</strong>g at a blank form. Perform the follow<strong>in</strong>g<br />

steps:<br />

1. Change the Caption property of the form to Bitmap Test Program.<br />

2. Click on the Additional tab on the Component Palette, choose the Image component,<br />

and place the component on the form.<br />

161<br />

5

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

Saved successfully!

Ooh no, something went wrong!