Example: Adding a Method to TextField Class

This example adds to the TextField class a method that selects all of the text in the text box.

winclass TextField : TextField
   SelectAll ()
      STRING sKey1, sKey2
      switch (GetGUIType ())
         case mswnt, msw2003
            sKey1 = "<Ctrl-Home>"
            sKey2 = "<Shift-Ctrl-End>"
         case mswvista
            sKey1 = "<Ctrl-Up>"
            sKey2 = "<Shift-Cmd-Down>"
      // return cursor to 1,1
      this.TypeKeys (sKey1)
      // highlight all text 
      this.TypeKeys (sKey2)

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.