An object's scope determines the availability and accessibility of the data members, properties, and methods within that object. Using the earlier bicycle analogy, if you were to add a headlight only to your customized "bicycle object," the headlight would belong to that bicycle and to no other. If, however, the "basic model bicycle object" included a headlight, then all bicycle objects would inherit the presence of a headlight. The headlight could lie either within the scope of the ancestor bicycle object--in which case, a headlight would be a part of all descendant bicycle objects--or within the scope only of the customized bicycle object, and available only to that bicycle.
Likewise, all data members, properties, and methods declared within a class declaration are within the scope of the class, and are available to that class and its descendants.
When you write code in an event handler of an object that refers to properties, methods, or data members of the object itself, you don't need to preface these identifiers with the name of the object variable. For example, if you put a button and an edit box on a new form, you could write this event handler for the OnClick event of the button:
__fastcall TForm1::Button1Click(TObject *Sender);
{
Color = clFuchsia;
Edit1->Color = clLime;
}
The first statement colors the form. You could have written the statement like this:
Form1->Color = clFuchsia
It's not necessary, however, to put the Form1 qualifier on the Color property because the Button1Click method is within the scope of the TForm1 object. Any time you are within an object's scope, you can omit the qualifier on all properties, methods, and data members that are part of the object.
The second statement refers to the Color property of a TEdit object. Because you want to access the Color property of the TEdit1 object, not of the TForm1 object, you need to specify the scope of the Color property by including the name of the edit box, so the compiler can determine which Color property you are referring to. If you omit it, the second statement is like the first; the form ends up lime green, and the edit box control remains unchanged when the handler runs.
Because it's necessary to specify the name of the edit box whose Color property you are changing, you might wonder why it's not necessary to specify the name of the form as well. This is unnecessary because the control Edit1 is within the scope of TForm1; it's declared to be a data member of TForm1.
More
Inside