NewEnum diffeculties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    #1

    NewEnum diffeculties

    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.Contain sPattern(sPatte rn) = 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.Pat h)
    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_oOriginalCFil esObject.GetPat ternFiles("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.GetP atternFiles(oPa ttern.Pattern)
    For Each oMyFile In oMyFiles
    Set ListItemX = lvwFilesA.ListI tems.Add(, , oPattern.Patter n)
    ListItemX.SubIt ems(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


  • Steve Gerrard

    #2
    Re: NewEnum diffeculties


    "Mike" <mbergerNO@SPAM skypoint.com> wrote in message
    news:UPydnVlter qDcMHeRVnyuQ@sk ypoint.com...[color=blue]
    >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.[/color]

    (big snip)
    [color=blue]
    >
    > Why can't I use the NewEnum method with my returned "subset" collection class
    > ?
    > Any ideas/opinions ?
    >[/color]

    I will bet $1 that you can't use any For Each ... iterator with your CFiles
    class, whether the one returned by GetPatternFiles or otherwise.

    While Class Builder does setup the NewEnum for you, it is easy to loose the
    required setting. It doesn't copy/paste, for instance.

    Assuming you already have

    Public Property Get NewEnum() As IUnknown
    'this property allows you to enumerate
    'this collection with the For...Each syntax
    Set NewEnum = mCol.[_NewEnum]
    End Property

    Click on the word NewEnum, then click on menu Tools, Procedure Attributes...
    Make sure NewEnum is the selected method, then click the Advanced button on the
    form.
    My $1 bet is that the Procedure ID is not -4. If you make it so, and click OK,
    you should be able to use For Each.



    Comment

    • Mike

      #3
      Re: NewEnum diffeculties

      Steve,
      That was the problem. I'm astonded at that. I have used the Class Builder
      many times, and I have made my own collection classes many times. In making
      my own, I've put in my own NewEnum, with the (-4) business. I have never
      noticed before that the Class Builder would garble that stuff up. I checked
      the 2 other collection classes that this project uses, and the NewEnum has
      the (-4). I wonder if putting in the new method (GetPatternFile s) somehow
      messed things up. Anyway, it works now, thanks for stating the obvious. I
      would have spent more time, thrasing around, not even thinking to make sure
      that Procedure Attribute setting was *still* correct.

      Mike

      "Steve Gerrard" <mynamehere@com cast.net> wrote in message
      news:fPydnbUbnp jGDsDeRVn-vw@comcast.com. ..[color=blue]
      >
      > "Mike" <mbergerNO@SPAM skypoint.com> wrote in message
      > news:UPydnVlter qDcMHeRVnyuQ@sk ypoint.com...[color=green]
      >>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.[/color]
      >
      > (big snip)
      >[color=green]
      >>
      >> Why can't I use the NewEnum method with my returned "subset" collection
      >> class ?
      >> Any ideas/opinions ?
      >>[/color]
      >
      > I will bet $1 that you can't use any For Each ... iterator with your
      > CFiles class, whether the one returned by GetPatternFiles or otherwise.
      >
      > While Class Builder does setup the NewEnum for you, it is easy to loose
      > the required setting. It doesn't copy/paste, for instance.
      >
      > Assuming you already have
      >
      > Public Property Get NewEnum() As IUnknown
      > 'this property allows you to enumerate
      > 'this collection with the For...Each syntax
      > Set NewEnum = mCol.[_NewEnum]
      > End Property
      >
      > Click on the word NewEnum, then click on menu Tools, Procedure
      > Attributes...
      > Make sure NewEnum is the selected method, then click the Advanced button
      > on the form.
      > My $1 bet is that the Procedure ID is not -4. If you make it so, and click
      > OK, you should be able to use For Each.
      >
      >
      >[/color]


      Comment

      Working...