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 />

■ Double-click<strong>in</strong>g the event handler’s name <strong>in</strong> the Object Inspector will display the<br />

Code Editor and take you to the section of code conta<strong>in</strong><strong>in</strong>g the event handler.<br />

■ Each event handler conta<strong>in</strong>s the function parameters needed to properly<br />

handle that event.<br />

<strong>C++</strong>Builder and VCL<br />

As I have said, VCL is a library written <strong>in</strong> Object Pascal. VCL is written <strong>in</strong> Object Pascal<br />

because it was written for Delphi. It made perfect sense for the people at <strong>Borland</strong> to take an<br />

already-exist<strong>in</strong>g class library and adapt it for use <strong>in</strong> <strong>C++</strong>Builder. There was no po<strong>in</strong>t <strong>in</strong><br />

start<strong>in</strong>g from scratch to build <strong>C++</strong>Builder when they could hit the ground runn<strong>in</strong>g by<br />

implement<strong>in</strong>g Delphi’s VCL. An added benefit is that users of Delphi can easily move to<br />

<strong>C++</strong>Builder, and vice versa. Because both are us<strong>in</strong>g the same VCL, you don’t have to learn<br />

a new framework when mov<strong>in</strong>g around <strong>in</strong> the Delphi/<strong>C++</strong>Builder family.<br />

<strong>C++</strong>Builder is a <strong>C++</strong> compiler, and VCL is an Object Pascal library. How does that work,<br />

exactly? Truthfully, you shouldn’t be concerned about how it works at the compiler level, but<br />

rather how it affects the way you program <strong>in</strong> <strong>C++</strong>Builder. The bottom l<strong>in</strong>e is that VCL is<br />

Object Pascal and is nearly <strong>in</strong>visible. Take the follow<strong>in</strong>g code snippet, for <strong>in</strong>stance:<br />

<strong>in</strong>t screenW = GetSystemMetrics(SM_CXSCREEN);<br />

<strong>in</strong>t screenH = GetSystemMetrics(SM_CYSCREEN);<br />

<strong>in</strong>t h = Ma<strong>in</strong>Form->Height;<br />

<strong>in</strong>t w = Ma<strong>in</strong>Form->Width;<br />

Ma<strong>in</strong>Form->Top = (screenH / 2) - (h / 2);<br />

Ma<strong>in</strong>Form->Left = (screenW / 2) - (w / 2);<br />

TPo<strong>in</strong>t cPt;<br />

GetCursorPos(cPt);<br />

h -= 150;<br />

w -= 150;<br />

Ma<strong>in</strong>Form->Height = h;<br />

Ma<strong>in</strong>Form->Width = w;<br />

for (<strong>in</strong>t i=0;iHeight = h + i;<br />

Ma<strong>in</strong>Form->Width = w + i;<br />

SetCursorPos(<br />

Ma<strong>in</strong>Form->Left + Ma<strong>in</strong>Form->Width,<br />

Ma<strong>in</strong>Form->Top + Ma<strong>in</strong>Form->Height);<br />

}<br />

SetCursorPos(cPt.x, cPt.y);<br />

Now, <strong>in</strong> this code, which is Object Pascal and which is <strong>C++</strong>? As far as you are concerned, it’s<br />

all <strong>C++</strong>. VCL and <strong>C++</strong> work together seamlessly to give you rapid application development<br />

us<strong>in</strong>g <strong>C++</strong>. VCL gives you RAD through components, and the rest of your code can be<br />

written <strong>in</strong> <strong>C++</strong>.<br />

153<br />

5

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

Saved successfully!

Ooh no, something went wrong!