background image
<< Class Hierarchy - Adding methods to a class | Class Hierarchy - Defining new class properties >>
Class Hierarchy - Redefining a method
<< Class Hierarchy - Adding methods to a class | Class Hierarchy - Defining new class properties >>
User's Guide
307
16 E
XTENDING
THE
C
LASS
H
IERARCHY
Adding methods to a class
case msw, motif
sKey1 = "<Ctrl-Home>"
sKey2 = "<Shift-Ctrl-End>"
case mac
sKey1 = "<Ctrl-Up>"
sKey2 = "<Shift-Cmd-Down>"
// return cursor to 1,1
this.TypeKeys (sKey1)
// highlight all text
this.TypeKeys (sKey2)
Note The keyword this refers to the object the method is being
called on.
The preceding method first decides which keys to press, based on the GUI. It
then presses the key that brings the cursor to the beginning of the field. It next
presses the key that highlights (selects) all the text in the field.
For more information on the syntax used in declaring new methods, see
"Method declaration" in online Help.
Example 2
To add a Tab method to the DialogBox class, you could add the following
4Test code to your frame.inc file (or other include file):
winclass DialogBox : DialogBox
Tab (INTEGER iTimes optional)
if (iTimes == NULL)
iTimes = 1
this.TypeKeys ("<tab {iTimes}>")
Redefining a method
There may be some instances in which you want to redefine an existing
method. For example, to redefine the GetCaption method of the Anywin
class, you use this 4Test code:
winclass AnyWin : AnyWin
GetCaption ()
// insert method definition here
Deriving a new
method from an
existing method
To derive a new method from an existing method, you can use the derived
keyword followed by the scope resolution operator (::).
The following example defines a GetCaption method for DialogBox that
prints the string "Dialog" before calling the built-in GetCaption method
(defined in the AnyWin class) and printing its return value:
winclass DialogBox : DialogBox
GetCaption ()
Print ("Dialog")
Print (derived::GetCaption ())