Добавил:
Upload
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:VB-2012 / 2-cеместр / Заочники(весна) / Методика / CH6 / NAryNode
.cls VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "NAryNode"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' ************************************************
' NAryNode.CLS
'
' Node class for N-ary tree.
Option Explicit
Public Children As New Collection
Public Box As Label
' ************************************************
' Delete the descendant node. Return True if the
' node is deleted.
' ************************************************
Public Function DeleteDescendant(target As NAryNode) As Boolean
Dim i As Integer
Dim child As NAryNode
' See if it's one of our children.
For i = 1 To Children.Count
If Children.Item(i) Is target Then
Children.Remove i
DeleteDescendant = True
Exit Function
End If
Next i
' It's not one of our children. Recursively
' check the descendants.
For Each child In Children
If child.DeleteDescendant(target) Then
DeleteDescendant = True
Exit Function
End If
Next child
End Function
' ************************************************
' Find the node that corresponds to the Label.
' ************************************************
Public Function FindNode(ctl As Label) As NAryNode
Dim node As NAryNode
Dim child As NAryNode
' See if we are the one.
If ctl = Box Then
Set FindNode = Me
Exit Function
End If
' See if a child can find it.
For Each child In Children
Set node = child.FindNode(ctl)
If Not (node Is Nothing) Then
Set FindNode = node
Exit Function
End If
Next child
Set FindNode = Nothing
End Function
' ************************************************
' Unload the node's label control.
' ************************************************
Private Sub Class_Terminate()
Unload Box
End Sub
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "NAryNode"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' ************************************************
' NAryNode.CLS
'
' Node class for N-ary tree.
Option Explicit
Public Children As New Collection
Public Box As Label
' ************************************************
' Delete the descendant node. Return True if the
' node is deleted.
' ************************************************
Public Function DeleteDescendant(target As NAryNode) As Boolean
Dim i As Integer
Dim child As NAryNode
' See if it's one of our children.
For i = 1 To Children.Count
If Children.Item(i) Is target Then
Children.Remove i
DeleteDescendant = True
Exit Function
End If
Next i
' It's not one of our children. Recursively
' check the descendants.
For Each child In Children
If child.DeleteDescendant(target) Then
DeleteDescendant = True
Exit Function
End If
Next child
End Function
' ************************************************
' Find the node that corresponds to the Label.
' ************************************************
Public Function FindNode(ctl As Label) As NAryNode
Dim node As NAryNode
Dim child As NAryNode
' See if we are the one.
If ctl = Box Then
Set FindNode = Me
Exit Function
End If
' See if a child can find it.
For Each child In Children
Set node = child.FindNode(ctl)
If Not (node Is Nothing) Then
Set FindNode = node
Exit Function
End If
Next child
Set FindNode = Nothing
End Function
' ************************************************
' Unload the node's label control.
' ************************************************
Private Sub Class_Terminate()
Unload Box
End Sub
Соседние файлы в папке CH6