📄 ccheckpoints.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "CCheckPoints"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
Attribute VB_Ext_KEY = "Collection" ,"CCheckPoint"
Attribute VB_Ext_KEY = "Member0" ,"CCheckPoint"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'local variable to hold collection
Private mCol As Collection
Public Sub ClearLinks()
Dim cp As CCheckPoint
For Each cp In mCol
cp.ClearLinks
Next cp
End Sub
Public Function InsertCheckpointObject(newObj As CCheckPoint, insertAt As Integer) As CCheckPoint
On Error GoTo eHandler
Dim i As Integer
Set InsertCheckpointObject = Nothing
If newObj Is Nothing Then Exit Function
newObj.index = insertAt
If insertAt > mCol.Count Then
' Insert as last item.
newObj.index = insertAt
mCol.Add newObj, newObj.GetID
Else
' Insert the item into our collection before the item that
' currently occupies the position indicated.
mCol.Add newObj, newObj.GetID, mCol(insertAt).GetID
For i = mCol.Count To insertAt + 1 Step -1
mCol(i).index = i
Next i
End If
Set InsertCheckpointObject = newObj
Exit Function
eHandler:
End Function
Public Function Copy() As CCheckPoints
On Error GoTo eHandler
Set Copy = Nothing
Dim newObj As CCheckPoints
Set newObj = New CCheckPoints
Dim obj As CCheckPoint
For Each obj In mCol
newObj.Add obj.Copy
Next obj
Set Copy = newObj
Set newObj = Nothing
Exit Function
eHandler:
LogError "CCheckPoints", "Copy", Error(Err), False
End Function
Public Function ItemByName(name As String) As CCheckPoint
On Error GoTo eHandler
Set ItemByName = Nothing
Dim cp As CCheckPoint
For Each cp In mCol
If cp.name = name Then
Set ItemByName = cp
Set cp = Nothing
Exit Function
End If
Next cp
Exit Function
eHandler:
LogError "CCheckPoints", "ItemByName", Error(Err)
End Function
Public Function Add(Optional newItem As CCheckPoint = Nothing, Optional AutoIndex As Boolean = True) As CCheckPoint
On Error GoTo eHandler
Set Add = Nothing
' Create a new object
Dim objNewMember As CCheckPoint
If newItem Is Nothing Then
Set objNewMember = New CCheckPoint
Else
Set objNewMember = newItem
End If
' Automatically calculate the index value to place the
' new member at the end of our list of checkpoints.
If AutoIndex Then
Dim highest As Integer
Dim item As CCheckPoint
highest = 0
' Find the current highest index.
For Each item In mCol
If item.index > highest Then
highest = item.index
End If
Next
' Add the new index.
objNewMember.index = highest + 1
End If
' Add the object to our collection.
mCol.Add objNewMember, objNewMember.GetID
' Return the object created
Set Add = objNewMember
Exit Function
eHandler:
LogError "CCheckPoints", "Add", Error(Err)
End Function
Public Function Import(line As String) As Boolean
On Error GoTo eHandler
Import = False
' Pass it to each of our checkpoints for processing.
For Each cp In mCol
cp.Import line
If GCancelImport Then Exit Function
Next
Import = True
Exit Function
eHandler:
LogError "CCheckPoints", "Import", Error(Err)
End Function
Public Property Get item(vntIndexKey As Variant) As CCheckPoint
Attribute item.VB_UserMemId = 0
On Error Resume Next
Set item = Nothing
'used when referencing an element in the collection
'vntIndexKey contains either the Index or Key to the collection,
'this is why it is declared as a Variant
'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
Set item = mCol(vntIndexKey)
End Property
Public Property Get Count() As Long
'used when retrieving the number of elements in the
'collection. Syntax: Debug.Print x.Count
Count = mCol.Count
End Property
Public Sub Remove(vntIndexKey As Variant)
'used when removing an element from the collection
'vntIndexKey contains either the Index or Key, which is why
'it is declared as a Variant
'Syntax: x.Remove(xyz)
mCol.Remove vntIndexKey
End Sub
Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
'this property allows you to enumerate
'this collection with the For...Each syntax
Set NewEnum = mCol.[_NewEnum]
End Property
Private Sub Class_Initialize()
'creates the collection when this class is created
Set mCol = New Collection
End Sub
Private Sub Class_Terminate()
'destroys collection when this class is terminated
Set mCol = Nothing
End Sub
' Reorder the items in our collection by index.
Public Sub Reorder()
Dim temp As Collection
Dim i As Integer
If mCol.Count < 1 Then Exit Sub
Set temp = mCol
Set mCol = Nothing
Set mCol = New Collection
i = 0
Do While temp.Count > 0
Dim obj As Object
Dim j As Integer
Dim smallest As Integer
i = i + 1 'Incremement the new index.
'***************************************
' Find the object with the lowest index.
'***************************************
smallest = 1
For j = 1 To temp.Count
If temp(j).index < temp(smallest).index Then
smallest = j
End If
Next j
Set obj = temp(smallest)
obj.index = i
mCol.Add item:=obj, key:=obj.GetID
temp.Remove obj.GetID
Set obj = Nothing
Loop
End Sub
Public Function Save(arc As CArchive) As Boolean
On Error GoTo eHandler
Save = False
Dim cp As CCheckPoint
For Each cp In mCol
If cp.Save(arc) = False Then Exit Function
Set cp = Nothing
arc.SaveItem aiBLANKLINE
Next
Save = True
Exit Function
eHandler:
LogError "CCheckPoints", "Save", Error(Err)
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -