mandelbrot Posted July 1, 2005 Posted July 1, 2005 Dear All, This is my first post in the forum, though I've posted loads of times in XVBT, so I'll make this a nice meaty one for the experts (I hope). Presently, I have defined a data tree structure to hold diary information. The structure works something like: Event (container) | +- Event (container) | +- Action (container) | | | +- Causality | +- Causality Basically, each event can contain further events or an action or causality. Actions can only contain causalities. Each object that changes invokes a change event. Each container that changes invokes a change event. My problem is that I don't know how to promote change events up the hierachy :confused:. If anyone could point me in the right direction, I would really appreciate it. Many thanks in advance, Paul. Quote
Machaira Posted July 1, 2005 Posted July 1, 2005 (edited) Off the top of my head: Each object could contain a Parent property that gets assigned when you create the object. Raise the Change event to the parent. Am I missing something? Here's some quick code: Public Class BaseObject Private _parent As BaseObject Private _name As String Private _children As New Collection Public Property Parent() As BaseObject Get Return _parent End Get Set(ByVal Value As BaseObject) If _parent Is Nothing Then _parent = New BaseObject _parent = Value End Set End Property Public Property Name() As String Get Return _name End Get Set(ByVal Value As String) _name = Value End Set End Property Public Property Children() Get Return _children End Get Set(ByVal Value) End Set End Property Public Sub AddChild(ByVal child As Object) child.Parent = Me _children.Add(child) End Sub Public Sub Change() Debug.WriteLine("Change handled by BaseObject: " & Name) End Sub End Class Public Class EventObject Inherits BaseObject Public Shadows Sub Change() Debug.WriteLine("Change event handled by EventObject: " & Name) Me.Parent.Change() End Sub End Class Public Class ActionObject Inherits BaseObject Public Shadows Sub Change() Debug.WriteLine("Change event handled by ActionObject: " & Name) Me.Parent.Change() End Sub End Class Public Class CasualtyObject Private _parent As ActionObject Private _name As String Public Sub New() _parent = New ActionObject End Sub Public Property Parent() As ActionObject Get Return _parent End Get Set(ByVal Value As ActionObject) _parent = Value End Set End Property Public Property Name() As String Get Return _name End Get Set(ByVal Value As String) _name = Value End Set End Property Public Sub Change() Me.Parent.Change() End Sub End Class 'test bed Dim obj As New EventObject Dim child As Object Dim child2 As Object obj.Name = "Parent" child = New EventObject CType(child, EventObject).Name = "Child 1" obj.AddChild(child) child = New ActionObject CType(child, ActionObject).Name = "Child 2" child2 = New CasualtyObject CType(child2, CasualtyObject).Name = "Child 3" child.AddChild(child2) obj.AddChild(child) CType(child2, CasualtyObject).Change() Edited July 1, 2005 by Machaira Quote Here's what I'm up to.
mandelbrot Posted July 1, 2005 Author Posted July 1, 2005 I can see where you're coming from, Machaira, the only problem there is that, if branch C contains D, E and F, then even if one of the nodes fires a Change event, how does B, the parent of C know that the change event has been fired? I suppose one option is to use the idea you have and include a reference to the ultimate parent - this would fire a change. It sounds a little messy, but it might work. Trust me, Machaira - you know more than I at this stage! LOL! Paul. Quote
mandelbrot Posted July 1, 2005 Author Posted July 1, 2005 Machaira, I've just read the code you've added there - that does make sense. You've defied a base class that is inherited by each object... I can see that working, after all, it's only the ultimate parent that needs to be referenced for change. I'll give that a go, and see how it works! Please accept my profuse thanks! :) Paul. Quote
Machaira Posted July 1, 2005 Posted July 1, 2005 NP. Free free to post any follow-up if you have problems with it. I whipped it up in a few minutes so there might be some gotchas that develop. :) Quote Here's what I'm up to.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.