Scope Resolution – Very Important!

 If code is written for a method in a parent class, that code is executed when the method is fired. When you create a subclass or object based on the parent class, the subclass or object automatically inherits all the methods of the parent class. However, you can inadvertently overwrite the parent class method code when inserting code for the method in the subclass or object. The code you insert blocks the parent class method code from firing unless you do something to make sure the parent class method code is not blocked. What you do is use "scope resolution".

When you need to modify a method for an object or a subclass, you must use either (a) the Visual FoxPro Scope Resolution Operator or (b) the DODEFAULT() function to make sure that the code in the parent class method is executed.

For example, let’s say you need to add code to the Init event of a form based on the VPMFORMS Form_Toolbar class. You don’t want to block the execution of the code in the Form_Toolbar class’s Init event. Here’s what you would do:

1.   First, you would open the Form_Toolbar class in the Class Designer and look at its Init event code to determine whether your code should be run before or after the code in the Init method of the Form_Toolbar class.

2.   Then, you would open your form in the Form Designer and insert either of the following two lines into the Init event:

Form_Toolbar::Init

   or

DODEFAULT()

3.   Finally, you would insert your code into the form’s Init event (a) before the scope resolution line if you want your code to run before the code in the Form_Toolbar class’s Init event or (b) after the scope resolution line if you want your code to run after the Form_Toolbar’s Init event.

If you put your code in the Init event of the form without using the scope resolution line, the code in the Form_Toolbar class’s Init event will be blocked and will not execute.

More:

Setting Up VFP Options for Form and Control Classes