Bazaar collection object behavior of changing attributes of stored objects (1 Viewer)

mdlueck

Sr. Application Developer
Local time
Today, 10:01
Joined
Jun 23, 2011
Messages
2,631
Greetings, I have never seen Access 2007 / VBA do ANYTHING this strange before...

For some reason I see the "active" attribute of a custom class flip stored in a Collection object flip from True to False when the code reaches the next LOC which returns the newly created object instance to the caller.

Looking at the code, I would think that the object is safely stored in the m_PrivateCollection collection object and do not know what to make out of seeing data change within that m_PrivateCollection collection storage object.

The Add method code is as follows:
Code:
'Add a new clsObjAdminPickListStandardAQEItem item to the collection
Public Function Add(ByVal intAuthID As Integer, ByVal strAuthUsername As String, ByVal strLogtimestamp As String, ByVal intID As Integer, ByVal intSort As Integer, ByVal boolActive As Boolean, ByVal strTitle As String, ByVal boolAQEFlg As Boolean) As clsObjAdminPickListStandardAQEItem
On Error GoTo Err_Add

  Dim newItem As New clsObjAdminPickListStandardAQEItem
  Dim Key As Variant

  With newItem
    .authid = intAuthID
    .authusername = strAuthUsername
    .logtimestamp = strLogtimestamp
    .id = intID
    .sort = intSort
    .active = boolActive
    .title = strTitle
    .aqeflg = boolAQEFlg
    Key = CStr(.id)
  End With

  'add to the private collection
  m_PrivateCollection.Add newItem, Key

[B][COLOR=Red]  Set Add = newItem[/COLOR][/B]

Exit_Add:
  Set newItem = Nothing
  Exit Function

Err_Add:
  Call errorhandler_MsgBox("Class: clsObjAdminPickListStandardAQEItems, Function: Add()")
  Add = False
  Resume Exit_Add

End Function
The LOC marked in RED is where I see the stored object's active value change from True to False in the Watches window. (Yes, within the m_PrivateCollection collection object of the class instance.)

So active = True gets passed in to the Add method, gets assigned to the newItem object, is successfully added to the m_PrivateCollection collection, after which the newItem object becomes the return value of the method and THAT act changes the active value to False within the m_PrivateCollection collection. WHY?!!?!?

And yes, I even went through a decompile / compact / recompile process to make sure that was not the reason for the odd behavior.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 15:01
Joined
Sep 12, 2006
Messages
15,650
just clutching at straws, but maybe there is already an item in the collection with an id of intid -

what would happen if you took this out of the function

'add to the private collection
m_PrivateCollection.Add newItem, Key

and added the returned object after the function completes.



m
 

mdlueck

Sr. Application Developer
Local time
Today, 10:01
Joined
Jun 23, 2011
Messages
2,631
Digging a bit deeper, I drilled into the Item class which Item instances are collected in the Items class.

Code:
[COLOR=Red](*)Public Property Let active(ByVal newActive As Boolean)[/COLOR]
On Error GoTo Err_Active

  boolActive = newActive
'   False        True

Exit_Active:
   [B][COLOR=Black]Exit Property[/COLOR][/B]

Err_Active:
  Call errorhandler_MsgBox("Class: clsObjAdminPickListStandardAQEItem, Property: Let active()")
  Resume Exit_Active

End Property
Stepping through this code, I see the True state come into the Let method via newActive and after the "boolActive = newActive" LOC, boolActive is STILL False!!! rrrrr?????

P.S. For some reason the args being passed into the Item class AND the attributes themselves BOTH show up as variables within the Item class object. So the passed in value of True held longer than the internal class storage variable boolActive, thus my prior confusion, I was looking at the incorrect active variable.
 
Last edited:

mdlueck

Sr. Application Developer
Local time
Today, 10:01
Joined
Jun 23, 2011
Messages
2,631
but maybe there is already an item in the collection with an id of intid -

This is the first Add to a brand new empty collection object.

j
what would happen if you took this out of the function

'add to the private collection
m_PrivateCollection.Add newItem, Key

I commented out the Add. As I found already, something is going wrong when the new Item instance is being created / initialized.

A subsequent instance correctly retains the boolActive = True flag, however that instance has True for both class attribute bool values (boolActive / boolAQEFlg) however the passed in arg values show active = True and aqeflg = False. (Which like I said, I have no idea why the VBA watches window even displays those values (args to Let calls) as those should not be persistent. ???? :confused:
 

mdlueck

Sr. Application Developer
Local time
Today, 10:01
Joined
Jun 23, 2011
Messages
2,631
P.S. For some reason the args being passed into the Item class AND the attributes themselves BOTH show up as variables within the Item class object. So the passed in value of True held longer than the internal class storage variable boolActive, thus my prior confusion, I was looking at the incorrect active variable.

Never mind on this one... I get what VBA is trying to tell me, I think.

The reason I see "double" is I think that the internal class storage variables are shown as they are defined at the class level, and also VBA watches window shows the Get Properties as class attributes.

I can not understand, then, why I would see discrepancies between the Get Properties and the Variables they represent.

I realized that watches could not be showing me the Let arguments as I prefix all of those variables with "new*". This explanation makes more sense.
 

mdlueck

Sr. Application Developer
Local time
Today, 10:01
Joined
Jun 23, 2011
Messages
2,631
Resolved now... another VBA compiler bug. To create the new boolean property, I merely copied the other boolean property and then renamed. I missed a couple of spots to rename, namely did not update the name of the return variable in the Get property.

I had:
Code:
'aqeflg API's
Public Property Get aqeflg() As Boolean
On Error GoTo Err_AQEFlg

  [B][COLOR=Red]active = boolAQEFlg[/COLOR][/B]

Exit_AQEFlg:
  Exit Property

Err_AQEFlg:
  Call errorhandler_MsgBox("Class: clsObjAdminPickListStandardAQEItem, Property: Get aqeflg()")
  [B][COLOR=Red]active = False[/COLOR][/B]
  Resume Exit_AQEFlg

End Property
Would have been nice for the compiler to gripe that active was not a declared variable. :banghead:

I finally found this by taking the Item class and copying that one class to a test database, and developing a driver harness to exercise just the Item class alone. Stepping through the code, all of a sudden I see the trace jump from AQEFlg code to Active code... rrrr!?!?!?!! Thus found the bug.
 

Users who are viewing this thread

Top Bottom