:: Scope Resolution Operator Examples

The following example creates a form and adds two command buttons to the form. By clicking either button, you can exit the form – the second button, cmdAnotherButton, calls the Click procedure from cmdQuit. This action is possible because of subclassing. The scope resolution operator calls the parent class code for the subclassed object.

frmMyForm = CREATEOBJECT("Form")
frmMyForm.Width  = 450
frmMyForm.Height   = 100
frmMyForm.Caption  = "Scope Resolution Example"
frmMyForm.AutoCenter =.T.
frmMyForm.AddObject("cmdQuit","cmdQuitButton")
frmMyForm.AddObject("cmdAnother","cmdAnotherButton")
frmMyForm.SHOW       && Display the form
READ EVENTS        && Start event processing

The following example defines two command buttons. The first button will be used to subclass the second button. The subclassing can be seen by the FontBold and ForeColor properties which are defined for cmdQuit, but never explicitly set for the cmdAnotherButton. We are defining cmdAnotherButton to be a subclass of the cmdQuitButton. As a result, this button will pick up all the attributes defined above for cmdQuitButton.

DEFINE CLASS cmdQuitButton AS CommandButton 
  Caption  = "\<Quit"   && Caption on command button
  Left   = 175    && Left edge of button
  Top    = 60     && Position for top of button
  Height   = 25     && Button height
  Visible  = .T.    && Show button on form
  FontItalic = .T.    && Turn on italic text
  ForeColor  = RGB(0,0,255) && Change button text color

  PROCEDURE Click
  WAIT WINDOW "Executing the CLICK procedure for cmdQuit." TIMEOUT 1
  CLEAR EVENTS     && Stop event processing, close Form
ENDDEFINE
DEFINE CLASS cmdAnotherButton AS cmdQuitButton

  Caption = "Click to quit"
  Left  = 175
  Top   = 30
  Height  = 25
   
  PROCEDURE Click
  WAIT WINDOW "Click event for button: cmdAnotherButton" TIMEOUT 1
  cmdQuitButton::Click
ENDDEFINE