1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "clsFields"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private pFields As Collection
Private pIndexes As Collection
'classe itérable
Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
Set NewEnum = pFields.[_NewEnum]
End Property
'-----------------------
'
Private Sub Class_Initialize()
Set pFields = New Collection
Set pIndexes = New Collection
End Sub
'
Private Sub Class_Terminate()
Set pFields = Nothing
Set pIndexes = Nothing
End Sub
'-----------------------
'méthode utilisée à l'initialisation uniquement
Public Sub add(ByRef field As clsField)
pFields.add item:=field
pIndexes.add item:=field.index, key:=field.key' field.index est numéral et field.key est une chaine caractère (unique)
End Sub
'
Public Sub update(ByRef field As clsField)
'recherche de l'instance à partir des indices "restants" (ie pas encore utilisés pour la mise à jour)
Dim index As Variant: For Each index In pIndexes
If pFields(index:=index).key = field.key Then
pFields(index:=index).update field:=field
'les clés des instance mise à jour sont nettoyées au fur et à mesure
pIndexes.Remove index:=field.key
Exit Sub
End If
Next index
pFields.add item:=field
pIndexes.add item:=field.index, key:=field.key
End Sub |
Partager