Removing then Adding Accelerators Fails


Id: 12335.1
Type: Bug Bug
Current Status: Resolution Identified


23 Oct 2003 Open Paul Yeager
I am trying to remove accelerators and then add them back in again.  When I use the RemoveAccelerator method, it seems to not remove anything.  How do I remove accelerators?
28 Oct 2003 Resolution Identified

Ah - a brief look at the code and I think I see the problem. This code in the control:

Public Function RemoveAccelerator(ByVal vKey As Variant) As Boolean
Dim iIdx As Long
Dim i As Long
   iIdx = Index(vKey)
   If iIdx > 0 Then
      If m_iCount > 1 Then
         For i = iIdx To m_iCount - 1
            LSet m_tAccel(i) = m_tAccel(i + 1)
         Next i
         ' BUG HERE
         ReDim Preserve m_tAccel(1 To m_iCount) As tAccel
         m_iCount = 0
         Erase m_tAccel
      End If
   End If
End Function

Looks to me like it has a bug - although the accelerator is allegedly removed, the count of the array isn't decremented. Therefore you'll always end up with at least one accelerator still there.