I found it somewhere, it gets around twinBASIC/VBA's inability for objects to cast themselves to specific interfaces by creating an 'invisible' metaclass type thing. This will help me to create a userfaciing object that changes its type based on context or a setting. Ive been playinga round with it and changing it  a bit, do you think its well written?

Anyways, my question is...i'd like to be able to also have it delete objects (or rather set them back to a default state like Nothing)
Ive tried all sorts of things...if i retreive the metaobject (and its objects) froim the mgr collection...i can change their values from there and it does get reflected in a mutable way like this class should....but no matter what I try i cannot get them to revert back to a default state....
So the code for that rn is incomplete and does not reflect all ive done....but ive tried setting the obejcts to nothing....setting the objects to new objects of that type....calling class_terminate methods....it never reflects the changes in the original... so help me out:

Module mObjMgr

    ' add your procedures here
    Sub test()
        Dim objA As New objVal, _
            objB As New objVal
        
        ' create objects and plug values
        objA.[__val__] = 5
        objB.[__val__] = "kaas"
        
        '✅byref behavior check
        objA.[__val__] = 555 'change gets reflected in collection, also as metaval
        
        '✅ def member behavior to act as variable
        objB = "lekkerrrr"
        objB.AddDerived("smerig man", "B")
        objB.AddDerived("kinda average", "C")
        
        objMgr.Purge()
        
        
    End Sub

    
    
End Module

Class objValColl
    Private  __coll__ As New Collection
    
    Public Sub Add(ByRef objVal As objVal, ByRef key As String)
        [__coll__].Add(objVal, key)
    End Sub
    
    Public Function Get(ByRef key As String) As objVal
        Return [__coll__].Item(key)
    End Function
    
End Class

Class objVal
    
    Public __val__ As Variant
    Private __metaVal__ As metaVal
    
    Sub Class_initialize()
        Dim mVal As metaVal = New metaVal(Me)
        Set [__metaVal__] = mVal
        objMgr.Add(mVal)
    End Sub
    
    Public Sub AddDerived(ByRef derivedVal As objVal, ByRef key As String)
        __metaVal__.addDerived(derivedVal, key)
    End Sub
    
    Public Sub AddDerived(ByRef derivedVal As Variant, ByRef key As String)
        objMgr.InhibitNext("population of derived member [key=" & key & "] to ObjValMgr collection prevented ") 'prevent adding of derived val to top objmgr list
        Dim derived As objVal
        Set derived = New objVal()
         
        __metaVal__.addDerived(derived, key)
    End Sub
    
    
    [DefaultMember]
    Public Property Get Val() As Variant
        Return [__val__]
    End Property
    
    [DefaultMember]
    Public Property Let Val(val As Variant)
        __val__ = val
    End Property
    
    Private Sub class_terminate()
        Debug.Print "bye"
    End Sub
    
    Public Sub Purge()
        class_terminate()
    End Sub
    
        
End Class

Class metaVal
    
    Public  __public__   As objVal
    Private __topLevel__ As objVal
    Private __derived__  As objValColl
    
    Private Sub Class_initialize()
        Set __derived__ = New objValColl
    End Sub
    
    Sub New(ByRef objVal As objVal)
        Set __public__ = objVal
        Set __topLevel__ = objVal
        
    End Sub
    
    Public Sub addDerived(ByRef objVal As objVal, key As String)
        If __derived__ Is Nothing Then Set __derived__ = New objValColl
        __derived__.Add(objVal, key)
    End Sub
    
    Public Sub setPublic_topLvl()
        Set [__public__] = [__topLevel__]
    End Sub
    
    Public Sub setPublic_derived(ByRef key As String)
        Set [__public__] = [__derived__].Get(key)
    End Sub
    
    ' [DefaultMember]
    ' Public Property Get Val() As Variant
    '     Return [__public__].Val
    ' End Property
    
    ' [DefaultMember]
    ' Public Property Let Val(newVal As Variant)
    '     [__public__].Val = newVal
    ' End Property
    
    
    
End Class


[PredeclaredId]
Class objMgr
    Private __coll__ As New Collection
    

    Public Sub Add(ByRef managedVal As metaVal)
        
        If __inhibit__ Then Exit Sub
        __coll__.Add(managedVal)
    End Sub
    
    Public Sub InhibitNext(Optional msg As String)
        __inhibit__(msg, True)
    End Sub
    
    [Description("Call this with arguments to inhibit the next population entry to the collection. Used by the 'add' method without any args, since in such case the return value will indicate wether the next entry should be inhibited.")]
    Private Function __inhibit__(Optional msg As Variant, Optional inhibitNext As Variant) As Variant
        Static __inhibit_next__ As Variant
        Static __msg__ As Variant
        
        If arg(msg).given Then __msg__ = msg
        If arg(inhibitNext).given Then __inhibit_next__ = inhibitNext
        
        If args(msg, inhibitNext).anyGiven Then Return Null
        
        If [__inhibit_next__] = True Then
            Debug.Print        __msg__
            __msg__          = Empty
            __inhibit_next__ = Empty
            Return True
        End If
        
    End Function
    
    Sub Purge()
        min = 1
        max = __coll__.Count
        For i = min To max
            Me.[__inhibit__]("preventing new collecting entities on purge", True)
            Dim newItem As objVal
            Dim item As metaVal = __coll__.Item(i)
            item.[__public__].Purge()
            ' item = "PLACEHOLDER" 'this gets reflected
            Set item = Nothing 
            
            
            
            
            
        Next i
        
        ' __coll__.Clear()
        
    End Sub
    
    
End Class