What is Self / Current_Object
<< Back
The keyword "Self" (or if you are an old timer like myself, you might refer that as "Current_Object") is the
starting point for resolving the object reference. It contains the object handle your code is currently at.
The value stored insides "Self" changes depends on which object you are in. Let's look at the following example
Use UI
Procedure ShowSelf
Showln (Name(Self)) " " Self
End_Procedure
Object oObject1 is a cObject
Send ShowSelf
End_Object
Object oObject2 is a cObject
Send ShowSelf
End_Object
InKey FieldIndex
Notice that depending who calls the "ShowSelf" procedure, it will display different object name on line 4.
Let's see what else we can do with "Self"
Use UI
Procedure ShowSelf
Showln (Name(Self)) " " Self
End_Procedure
Object oObject1 is a cObject
Send ShowSelf
End_Object
Object oObject2 is a cObject
Move Self to FieldIndex // Save the value of "Self" to a temp variable
Move (oObject1(Self)) to Self // Pretend that you are in oObject1
Send ShowSelf
Move FieldIndex to Self // Restore the value of "Self"
End_Object
InKey FieldIndex
You will see that program is going to output "oObject1" twice because we changed the value in "Self"
before sending "ShowSelf".
You can think of "Self" is just a global variable that is changed by the VDF runtime auto-magically,
depending on where your code is at. However, since it's a variable, that means its value can be changed
by you. It is unusual to change the content in "Self", but it will come in extremely handy if you
are doing "Eval" on the fly. We will deep dive into "Eval" in the future article.