04.08.2013 Views

Chapter 10 Using VFP's Object- Oriented Tools - dFPUG-Portal

Chapter 10 Using VFP's Object- Oriented Tools - dFPUG-Portal

Chapter 10 Using VFP's Object- Oriented Tools - dFPUG-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.

284 The Fundamentals of Visual FoxPro 6.0<br />

There are times when you might want the behavior of an event to be suppressed. (Are you<br />

picturing the peasant in Monty Python and the Holy Grail, hollering, “He’s repressing me…”?)<br />

For example, you can create your own pick list with a grid that features incremental<br />

search—as the user types a character, the highlight in the pick list repositions itself to the<br />

nearest entry containing those characters. The grid would have a text box in the column that’s<br />

being searched. As you know, the default behavior of the KeyPress event of a text box is to<br />

display the character typed in the text box. You don’t actually want the character typed to be<br />

displayed, so you would want that behavior—displaying the character—to be overridden.<br />

Use the NODEFAULT keyword in the event’s method to do this. For example, you could<br />

write code to trap the character being typed, perhaps storing it to a property of the pick list, and<br />

then using NODEFAULT to prevent the character from being displayed, like so:<br />

* they pressed an alphanumeric key<br />

nodefault<br />

* append the last key pressed to the keyboard buffer property<br />

this.cStuffInKBBuffer = this.cStuffInKBBuffer + chr(nKeyCode)<br />

* look for the complete string<br />

if not seek(upper(this.cStuffInKBBuffer))<br />

go this.nCurRecNum<br />

endif<br />

The actual code would be more complex because you would want to test for the time<br />

elapsed between keypresses, but you get the idea.<br />

Calling a parent’s method in addition to the local method<br />

Another task you’re likely want to perform is to call the parent’s method in addition to the code<br />

in the current method. In other words, this time you’re mixing the blue and the yellow colors,<br />

and want green. You can reference the code of the parent class using the :: operator (referred to<br />

as the scope resolution operator) or the DODEFAULT() keyword. The DODEFAULT()<br />

keyword is usually preferred because you don’t have to know the name of the parent class<br />

you’re referencing.<br />

Suppose the parent class is named cmdDrill and you’ve subclassed it with a name of<br />

cmdDrillLocation. The click event of cmdDrill has the following code:<br />

beep()<br />

If you simply put code in the Click method of the cmdDrillLocation subclass, you would<br />

end up overriding any code in the cmdDrill class’s Click method. To call the BEEP code in the<br />

cmdDrill class as well as the code in the Click event of the cmdDrillLocation class, you would<br />

use the following code:<br />

Dodefault()<br />

<br />

or<br />

cmdDrill::click()<br />

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

Saved successfully!

Ooh no, something went wrong!