5.6.11 Instance Expressions
Note
This section describes the implementation of MS-VBAL §5.6.11 Instance Expressions.
An instance expression is the keyword Me.
Static Semantics
MS-VBAL §5.6.11 describes instance expressions (Me) as values:
| Enclosing procedure | Me |
|---|---|
| In a class module | A value whose declared type is defined by the class module containing the enclosing procedure. |
| In a procedural ("standard") module | Statically invalid. |
Runtime Semantics
At run time, an instance expression (Me) represents the current instance of the type defined by the enclosing
class module, and has this type as its value type (MS-VBAL §5.6.11).
In line with MS-VBAL §5.6.11, RD-VBA implements Me as a simple runtime artifact, the current object, rather
than as an expression. The current object is a common concept in many programming languages, where it is often
written with the token this.
- The runtime injects an implicit
Me(ByVal) parameter into all instance member calls, pointed at the current object. - The runtime context supplies
Meas a VBObjectValue presenting the default interface of the enclosing class type. - The
Mevalue is pushed to the stack frame of instance member calls as any parameter is. See RD-VBAL §5.3.1.11 Procedure Invocation Argument Processing.
RuntimeExpressionEvaluator.EvaluateInstance resolves the name Me through ResolveValue, from
RuntimeEvaluationContext.Scope. RuntimeProcedureInvoker sets RuntimeEvaluationContext.Scope to the invoked
procedure's own Uri. RuntimeExpressionEvaluator.EvaluateSimpleName uses the same RuntimeEvaluationContext.Scope
to detect a self-reference to the executing procedure; see
RD-VBAL §5.6.10 Simple Name Expressions.
⏮️ RD-VBAL §5.6.10 Simple Name Expressions | ⏭️ RD-VBAL §5.6.12 Member Access Expressions