As the title already suggests, here the base-code for an implementation - which (other than a free-standing ADO-Rs), comes with support for "direct memory-access to already contained data"...
to allow for fast(er) enumerations on larger sets.
Note, that the Demo is currently dependent on RC6 -
but the only thing used from it, is the cArrayList (which wraps SafeArrays for VBs intrinsic DataTypes).
So, if you want to make the following few code-lines independent from it,
you could implement something similar (or work with "normal VB-arrays" directly in the cFld-Class)
Here's what the Form-TestCode currently looks like:
And here's the Demo-Zip:
DataTable.zip
Have fun!
Olaf
to allow for fast(er) enumerations on larger sets.
Note, that the Demo is currently dependent on RC6 -
but the only thing used from it, is the cArrayList (which wraps SafeArrays for VBs intrinsic DataTypes).
So, if you want to make the following few code-lines independent from it,
you could implement something similar (or work with "normal VB-arrays" directly in the cFld-Class)
Here's what the Form-TestCode currently looks like:
Code:
Option Explicit
Private Declare Function TextOutW Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As Long, ByVal nCount As Long) As Long
Private Rs As New cRec
Private Sub Form_Load()
Rs.Fields.Append "ID", vbLong
Rs.Fields.Append "Name", vbString
Rs.AddNew: Rs("ID") = 0: Rs("Name") = "Mr. X"
Rs.AddNew: Rs("ID") = 1: Rs("Name") = "Peter"
Rs.AddNew: Rs("ID") = 2: Rs("Name") = "Paul"
Rs.AddNew: Rs("ID") = 3: Rs("Name") = "Mary"
Rs.MoveFirst: Rs.Delete 'this should delete the first record ("Mr. X")
Caption = "Rec-Count: " & Rs.RecordCount 'this should report 3 in the Caption
Caption = Caption & " ...Click Me for Pointer-Listing"
Rs.MoveFirst 'the usual enumeration-loop
Do Until Rs.EOF
Debug.Print Rs!ID, Rs!Name
Rs.MoveNext
Loop
End Sub
Private Sub Form_Click() 'enumeration, directly from memory (without copying data)
FontName = "Arial": FontSize = 10: Cls
Dim L() As Long, S() As String, i As Long
If Not Rs("ID").BindToArray(L) Then MsgBox "Binding not possible": Exit Sub
If Not Rs("Name").BindToArray(S) Then MsgBox "Arr-Binding not possible": Exit Sub
For i = 0 To Rs.RecordCount - 1
TextOutW hDC, 5, i * 15, StrPtr(CStr(L(i))), Len(CStr(L(i)))
TextOutW hDC, 30, i * 15, StrPtr(S(i)), Len(S(i))
Next
Rs("ID").ReleaseArrayBinding L
Rs("Name").ReleaseArrayBinding S
End Sub
DataTable.zip
Have fun!
Olaf