A
Arnold Schrijver
I wrote a program that draws items to the screen and maintains a set of
Offset values.
There was a bug in the code, because objects were positioned wrongly. While
debugging
I found some peculiar behavior with the overloaded Property Offsets:
In class CanvasBlock:
------------------------------
Public Enum EOffsetTypes
HorizontalOffset = 0
VerticalOffset = 1
End Enum
'Update ArrayList with Horz/Vertical offsets, that are always
present.
Protected WriteOnly Property BlockOffset(ByVal offsetType As
EOffsetTypes) As Double
Set(ByVal offset As Double)
'Add new value to ArrayList1 at specified index (=
CInt(offsetType)).
End Set
End Property
'Store any additional Offsets in a separate ArrayList. Create
additional entries as needed.
Protected WriteOnly Property BlockOffset(Optional ByVal offsetIndex
As Integer = Nothing) As Double
Set(ByVal offset As Double)
If offsetIndex.Equals(Nothing) = True Then
'Add new value to ArrayList2
Else
'Add new value to ArrayList2 at specified offsetIndex .
End If
End Set
End Property
In the calling code:
------------------------------
'Correct. ArrayList1(0) is updated.
objBlock.Offsets(EOffsetTypes.HorizontalOffset) = 7.0
'Correct. ArrayList1(1) is updated.
objBlock.Offsets(EOffsetTypes.VerticalOffset) = 7.0
'Correct ArrayList2(1) is updated.
objBlock.Offsets(1) = 7.0
'Incorrect!! ArrayList1(0) is updated. The first overloaded method
with the Enum signature is called.
'Since the previous call succeeded, I would expect this call to
succeed as well. Strange? A bug?
objBlock.Offsets(0) = 7.0
Am I doing something wrong here? Can .NET not differentiate between
signatures with Integer and
Enums (which are basically also integer values), or is this a bug in .NET?
Cheers,
Arnold Schrijver.
Offset values.
There was a bug in the code, because objects were positioned wrongly. While
debugging
I found some peculiar behavior with the overloaded Property Offsets:
In class CanvasBlock:
------------------------------
Public Enum EOffsetTypes
HorizontalOffset = 0
VerticalOffset = 1
End Enum
'Update ArrayList with Horz/Vertical offsets, that are always
present.
Protected WriteOnly Property BlockOffset(ByVal offsetType As
EOffsetTypes) As Double
Set(ByVal offset As Double)
'Add new value to ArrayList1 at specified index (=
CInt(offsetType)).
End Set
End Property
'Store any additional Offsets in a separate ArrayList. Create
additional entries as needed.
Protected WriteOnly Property BlockOffset(Optional ByVal offsetIndex
As Integer = Nothing) As Double
Set(ByVal offset As Double)
If offsetIndex.Equals(Nothing) = True Then
'Add new value to ArrayList2
Else
'Add new value to ArrayList2 at specified offsetIndex .
End If
End Set
End Property
In the calling code:
------------------------------
'Correct. ArrayList1(0) is updated.
objBlock.Offsets(EOffsetTypes.HorizontalOffset) = 7.0
'Correct. ArrayList1(1) is updated.
objBlock.Offsets(EOffsetTypes.VerticalOffset) = 7.0
'Correct ArrayList2(1) is updated.
objBlock.Offsets(1) = 7.0
'Incorrect!! ArrayList1(0) is updated. The first overloaded method
with the Enum signature is called.
'Since the previous call succeeded, I would expect this call to
succeed as well. Strange? A bug?
objBlock.Offsets(0) = 7.0
Am I doing something wrong here? Can .NET not differentiate between
signatures with Integer and
Enums (which are basically also integer values), or is this a bug in .NET?
Cheers,
Arnold Schrijver.