JavaScript Editor js editor     Web development 

Main Page

Runs a parent class method from within a subclass method.



The :: operator is used to execute a parent class method from within a subclass method. When you create a subclass, the subclass methods are automatically inherited from the parent class. The :: operator makes it possible for you to execute the parent class method in the subclass method and then perform additional processing for the subclass method. The subclass definitions in the example demonstrate how the :: operator is used to execute the parent class method within a subclass method.

For additional information about the :: scope resolution operator, see Object-Oriented Programming.


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.

В Copy Code
frmMyForm = CREATEOBJECT("Form")
frmMyForm.Width  = 450
frmMyForm.Height   = 100
frmMyForm.Caption  = "Scope Resolution Example"
frmMyForm.AutoCenter =.T.
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.

В Copy Code
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

  WAIT WINDOW "Executing the CLICK procedure for cmdQuit." TIMEOUT 1
  CLEAR EVENTS     && Stop event processing
DEFINE CLASS cmdAnotherButton AS cmdQuitButton

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

See Also

JavaScript Editor js editor     Web development