|
-
Nov 21st, 2018, 03:54 PM
#10
Re: Create class for instantiation at runtime
Hmmm, well, the idea of a disconnected recordset is certainly interesting, but I'm thinking the lightweight object is more what I'm after.
But, before discarding the disconnected recordset, I tweaked on Dilettante's code (removing the one-to-many relationship, and just generally simplified it), and came up with the following:
Code:
Option Explicit
'
' Microsoft ActiveX Data Objects 6.1 Library <---- used as the ADO reference.
Dim rsShapedData As New ADODB.Recordset
'
Private Sub Form_Load()
Dim i As Long, j As Long
'
' Create and open disconnected recordset.
rsShapedData.ActiveConnection = "Provider=MSDataShape;Data Provider=None;"
rsShapedData.Open "SHAPE APPEND NEW adInteger AS [Field1], NEW adUnsignedTinyInt AS [Field2], NEW adLongVarWChar AS [Field3]", , adOpenStatic, adLockOptimistic
'
' Add some records.
For i = 1 To 10
rsShapedData.AddNew Array("Field1", "Field2", "Field3"), Array(i, 3 * i, "blah-blah" & CStr(i))
Next
'
' Dump the records.
rsShapedData.MoveFirst
Do
Debug.Print rsShapedData![Field1], rsShapedData![Field2], rsShapedData![Field3]
rsShapedData.MoveNext
Loop While Not rsShapedData.EOF
'
End Sub
That code is quite interesting, and certainly provides a way to track UDT-like array data in memory. Also, if Dilettante's one-to-many relationship were re-instated, it could handle UDT-like arrays nested in other UDT-like records, accomplishing (functionally) about everything UDTs will do with the added advantage of having all the ADO navigation procedures for "array" iteration. Also, as a straight-up object, these ADO recordsets could easily be put into Variants and/or passed anyway we like.
That, in and of itself, makes this thread worthwhile.
-----------------------
However, I think a lightweight object was more what I was thinking. Also, it'll give me the opportunity to learn more about COM objects. I found this post by Dex and this post by Trick. I'd really like to do it without the need for a TypeLib, so I studied Dex's ideas. However, Dex isn't creating the interface from scratch. Rather, he's showing us how to create a lightweight object using the IEnumVARIANT interface.
On the other hand, Trick is creating the interface and the object. But he's using a TypeLib to get it done. I'm going to further study Dex's approach, but I'm hoping there's a way to create the interface and instantiate the object without the need for a TypeLib.
Y'all Take Care,
Elroy
EDIT1: Ahhh, sorry Olaf. I took forever to compose my post, and didn't see yours until after I posted mine.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|