Tip of the day: Using computed property with weak reference

ComputedProperty ParentWindow As window1
Sub Set(value as ParentWindow)
if value<>Nil then
mParentWindow = new weakref(value)
else
mParentWindow = nil
end if
End
Function Get() as ParentWindow
if mParentWindow<>nil then
dim o as variant = mParentWindow.Value
Return o
end if
End
End ComputedProperty
Property Private mParentWindow As WeakRef
As you see we have a private property with the actual weakRef. The computed property getter checks if we have a WeakRef and provides value of it. We use a variant to avoid the need of explicit casting. For the setter we either set our weakRef property to nil or a new weakRef pointing to the target value.
Please use weak references always for references in data structures where a leaf references back to the tree.