Symptom: ParentRoutine Returns vcRoutine in VC 4.9
When a statement executes inside a process node of a ProcessExecutor, the correct return type of statement.ParentRoutine is vcProcessRoutine, because vcProcessRoutine derives from vcRoutine through class inheritance. In Visual Components 4.9 this is broken: ParentRoutine returns the underlying process routine wrapped incorrectly as a plain vcRoutine. The result is that properties defined on the process routine — such as a routine-level variable like Counter — are not reachable through the returned object, and printing the return value confirms the vcRoutine type instead of the expected subclass.
Workaround: Resolve the vcProcessRoutine from the Executor
There is no cast expression that converts the mis-wrapped vcRoutine back into a vcProcessRoutine; the type information was lost by the incorrect wrapping, not by Python-side typing. Instead, obtain the process routines exposed by the vcProcessExecutor itself and locate the one that matches the statement's parent routine, using either a name comparison or object equality. Confirm the exact accessor for the routine collection in the official vcProcessExecutor API reference for VC 4.9.
def OnStatementExecute(executor, statement):
target = statement.ParentRoutine
routine = None
# Iterate the executor's process routine collection
# (accessor name per the vcProcessExecutor API reference)
for pr in executor.ProcessRoutines:
if pr == target or pr.Name == target.Name:
routine = pr
break
if routine is not None:
print routine.Counter
Reading a Routine Variable such as Counter
Routine variables like Counter are properties on the vcProcessRoutine object, so once you hold a correctly typed reference, read the value with plain attribute access — no conversion expression is required. When the executor typing is correct, the direct access is a one-liner; with the 4.9 bug active, use the resolved reference from the workaround above.
def OnStatementExecute(executor, statement):
print statement.ParentRoutine.Counter
Verification
Print the type of the object before and after applying the workaround: statement.ParentRoutine prints as vcRoutine (the bug), while the matched object from the executor's routine collection must expose the process routine properties. Successful access to Counter without an attribute error confirms you hold the real vcProcessRoutine instance.
FAQ
Why does statement.ParentRoutine return vcRoutine instead of vcProcessRoutine?
This is a confirmed bug in Visual Components 4.9: the ParentRoutine property returns the underlying process routine wrapped incorrectly as its base class vcRoutine, even when the statement sits in a process node of a ProcessExecutor.
How do I get the vcProcessRoutine instance from a statement in a ProcessExecutor?
You cannot cast the mis-wrapped vcRoutine back; instead, get the process routines from the vcProcessExecutor and find the matching one by name or equality comparison against statement.ParentRoutine.
How do I read a process routine variable like Counter in OnStatementExecute?
Access it as a property on the correctly typed routine object: print statement.ParentRoutine.Counter. Under the VC 4.9 bug, first resolve the matching vcProcessRoutine from the executor, then read routine.Counter.