Objects Internals
From CacheWiki
[edit]
%this
At runtime inside the context of a method there is a variable %this which contains a reference to the current class.
Class MyPackage.MyClass Extends %Persistent
{
Method myMethod()
{
w !,%this
}
}
If this method is executed then you get the following output:
USER>d ##class(MyPackage.MyClass).%New().myMethod() 1@MyPackage.MyClass USER>
The %this variable is used by Cache to determine whether or not a private property is visible. So you can access the private properties of an object simply by setting %this to the oref of the object you want to examine. For example:
Class MyPackage.MyClass Extends %Persistent
{
Property myPrivateProperty As %String [ InitialExpression = "you can't see this", Private ];
}
You can access the private property of this class from the command line like this:
USER>s oMyClass=##class(MyPackage.MyClass).%New() USER>w oMyClass.myPrivateProperty W oMyClass.myPrivateProperty ^ <PRIVATE PROPERTY> USER>s %this=oMyClass USER>w oMyClass.myPrivateProperty you can't see this USER>
This can sometimes be a useful debugging technique.

