🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators RootObject
Created by Hans.karlsen on 2019-05-29 · Last edited by Vale.buyondo on 2026-02-12.

The RootObject operator is a member of the selfVM context. it returns the specific object instance that was used to open (root) the current ViewModel. It is read-only regarding the reference—meaning you cannot change which object is the root while the view is open—but you can modify the attributes of that object.

Example 1

selfVM.RootObject->notEmpty

This checks if the view is rooted

Example 2

selfVM.RootObject->safeCast(Thing).SomeString:='a new value'

Why is the selfVM.RootObject not typed but requires a cast to be used with the real root? Because OCL is a statically typed language and selfVM is context sensitive - meaning it is available in all ViewModels - there is no one answer to what type the RootObject should have. If you are in the context of a ViewModel, you will however know what type it has and can safely cast.