- Код: Выделить всё
Option Explicit
Private Declare Function GetMem4 Lib "msvbvm60" (Src As Any, Dst As Any) As Long
Private Sub Form_Load()
Dim Col As Collection, i As Long
Set Col = New Collection
Col.Add "ssss", "item1"
Col.Add "ssss", "item2"
Col.Add "ssss", "item3"
Col.Add "ssss", "item4"
Col.Add "ssss", "item5"
For i = 1 To Col.Count
Debug.Print ColKey(i, Col)
Next
End Sub
Private Function ColKey(ByVal Index As Long, Col As Collection) As String
Dim lpSTR As Long, Ptr As Long, Key As String
If Col Is Nothing Then Exit Function
Select Case Index
Case Is < 1, Is > Col.Count: Exit Function
Case Else
Ptr = ObjPtr(Col)
Do While Index
GetMem4 ByVal Ptr + 24, Ptr
Index = Index - 1
Loop
End Select
GetMem4 ByVal VarPtr(Key), lpSTR
GetMem4 ByVal Ptr + 16, ByVal VarPtr(Key)
ColKey = Key
GetMem4 lpSTR, ByVal VarPtr(Key)
End Function