I have used the Class Builder in my vb6 project to create a collection class
for my project. Using Class Builder automatically create the NewEnum method
for you, and I've done this a hundred time, and everything is good. So, I
have a CFiles class that contains a collection of CFile objects. I added a
method to the CFiles object, GetPatternFiles, which returns a CFiles object.
The point of this is for my CFiles object to return a subset of CFile
objects, in the returned CFiles collection. I search the existing mCol
variable to see if each individual CFile object meets a certain criteria,
and if so, .Add it to the "subset" CFiles object.
in class CFiles
'-----------------------------------------------------------------------------------------
Public Function GetPatternFiles(sPattern As String) As CFiles
'-- This variable will be used in the For...Each to search my existing
mCol variable
Dim oMyFile As CFile
'-- We will return a new subsetted CFiles collection from ourselves
Dim oMyReturnFiles As CFiles
'--
Dim oMyNewFile As CFile
For Each oMyFile In mCol
If oMyFile.ContainsPattern(sPattern) = True Then
'-- Create a new "subset" CFiles collection to return to caller
If oMyReturnFiles Is Nothing Then
Set oMyReturnFiles = New CFiles
End If
Set oMyNewFile = oMyReturnFiles.Add(oMyFile.Path)
End If
Next
Set GetPatternFiles = oMyReturnFiles
Set oMyReturnFiles = Nothing
End Function
'-----------------------------------------------------------------------------------------
Seemingly, all this works, now comes the exception of the NewEnum method of
the CFiles collections.
When the caller of m_oOriginalCFilesObject.GetPatternFiles("test") gets the
returned CFiles collection, I cannot do a For...Each using that CFiles
object
In specific a
'-- The new CFiles object that will be a subset of the existing CFiles
object
Dim oMyFiles As CFiles
'-- Used in the For ... Each
Dim oMyFile As CFile
Dim ListItemX As ListItem
'-- m_oPatterns is a collection of oPattern objects, which has a String
".Pattern" property
For Each oPattern In m_oPatterns
Set oMyFiles = m_oMyFiles.GetPatternFiles(oPattern.Pattern)
For Each oMyFile In oMyFiles
Set ListItemX = lvwFilesA.ListItems.Add(, , oPattern.Pattern)
ListItemX.SubItems(1) = oMyFile.Path
Next
Next
VB6 gags on the
For Each oMyFile in oMyFiles with an
Run-time error '438':
Object doesn't support this property or method error
Why can't I use the NewEnum method with my returned "subset" collection
class ?
Any ideas/opinions ?
Mike