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.

VCL Components<br />

<strong>C++</strong>Builder displays an icon represent<strong>in</strong>g the component on the form. This icon is used to<br />

access the component at design time <strong>in</strong> order to change the component’s properties, but the<br />

icon does not show up when the program runs. Nonvisual components have properties,<br />

methods, and events just like visual components do.<br />

The Name Property<br />

NOTE<br />

The Name property serves a vital role <strong>in</strong> components. As mentioned earlier, when you place<br />

a component on a form, <strong>C++</strong>Builder goes to work <strong>in</strong> the background while you ponder your<br />

next move. One th<strong>in</strong>g <strong>C++</strong>Builder does is create a po<strong>in</strong>ter to the component and assign the<br />

Name property as the variable name. For example, let’s say you place an Edit component on<br />

a form and change the Name property to MyEdit. At that po<strong>in</strong>t <strong>C++</strong>Builder places the follow<strong>in</strong>g<br />

<strong>in</strong> the header file for the form:<br />

TEdit* MyEdit;<br />

When the application runs, <strong>C++</strong>Builder creates an <strong>in</strong>stance of the TEdit class and assigns it<br />

to MyEdit. You can use this po<strong>in</strong>ter to access the component at runtime. To set the text for<br />

the edit control, you would use<br />

MyEdit->Text = “Jenna Lynn”;<br />

<strong>C++</strong>Builder also uses the Name property when creat<strong>in</strong>g event handler names. Let’s say that you<br />

wanted to respond to the OnChange event for an Edit component. Normally, you double-click<br />

the Value column next to the OnChange event to have <strong>C++</strong>Builder generate an event handler<br />

for the event. <strong>C++</strong>Builder creates a default function name based on the Name property of the<br />

component and the event be<strong>in</strong>g handled. In this case, <strong>C++</strong>Builder would generate a function<br />

called MyEditChange().<br />

You can change the Name property at any time, provided that you change it only via the Object<br />

Inspector. When you change a component’s Name property at design time, <strong>C++</strong>Builder goes<br />

through all the code that <strong>C++</strong>Builder had previously generated and changes the name of the<br />

po<strong>in</strong>ter and all event-handl<strong>in</strong>g functions.<br />

<strong>C++</strong>Builder will change all the code generated by <strong>C++</strong>Builder to reflect<br />

the new value of the component’s Name property, but it will not modify<br />

any code you wrote. In other words, <strong>C++</strong>Builder will take care of<br />

modify<strong>in</strong>g the code it wrote, but it is up to you to update and ma<strong>in</strong>ta<strong>in</strong><br />

the code you wrote. Generally speak<strong>in</strong>g, you should change the Name<br />

property when you <strong>in</strong>itially place the component on the form and leave<br />

it alone after that.<br />

273<br />

8

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

Saved successfully!

Ooh no, something went wrong!