THIS Object Reference

Example   See Also

Provides a reference to the current object in event code or in a class definition.

Syntax

THIS.PropertyName | ObjectName

Arguments

PropertyName

Specifies a property to set or get for the object.

ObjectName

Specifies an object in the class.

Remarks

THIS provides a convenient way of referring to the current object when writing event-handling programs in a form. For example, this Click Event program for a command button sets the button's caption to the current time:

this.caption = time()

Using THIS instead of explicitly referring to the current object by name (for example, thisform.command1.caption) makes program code portable between objects, because it avoids the object's name, and automatically encapsulates the object's parent class.

THIS also allows you to reference a property or an object in a class definition. Methods in a class definition block can use THIS to specify a property or object that will exist when the class is created.

Because multiple instances of objects share the same method code, THIS always refers to the instance in which the code is executing. If there are multiple instances of an object, and one of the object's methods is called, THIS refers to the correct object.