473,840 Members | 1,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange behavior - Overloaded Property and Enum parameter - Bug?

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
HorizontalOffse t = 0
VerticalOffset = 1
End Enum

'Update ArrayList with Horz/Vertical offsets, that are always
present.
Protected WriteOnly Property BlockOffset(ByV al 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(Opt ional ByVal offsetIndex
As Integer = Nothing) As Double
Set(ByVal offset As Double)

If offsetIndex.Equ als(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.Offset s(EOffsetTypes. HorizontalOffse t) = 7.0

'Correct. ArrayList1(1) is updated.
objBlock.Offset s(EOffsetTypes. VerticalOffset) = 7.0

'Correct ArrayList2(1) is updated.
objBlock.Offset s(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.Offset s(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.
Nov 21 '05 #1
3 1864
"Arnold Schrijver" <ar************ *************@2 organize.com> schrieb:
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
HorizontalOffse t = 0
VerticalOffset = 1
End Enum

'Update ArrayList with Horz/Vertical offsets, that are always
present.
Protected WriteOnly Property BlockOffset(ByV al 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(Opt ional ByVal offsetIndex
As Integer = Nothing) As Double
Set(ByVal offset As Double)

If offsetIndex.Equ als(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.Offset s(EOffsetTypes. HorizontalOffse t) = 7.0

'Correct. ArrayList1(1) is updated.
objBlock.Offset s(EOffsetTypes. VerticalOffset) = 7.0

'Correct ArrayList2(1) is updated.
objBlock.Offset s(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.Offset s(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?

I am not able to repro this behavior with .NET 1.0 using the code below:

\\\
Public Enum Foo
Goo = 0
Baz = 1
End Enum

Public WriteOnly Property Test(Optional ByVal i As Integer = 0) As Object
Set(ByVal Value As Object)
Debug.WriteLine ("'Test(Integer )'")
End Set
End Property

Public WriteOnly Property Test(ByVal i As Foo) As Object
Set(ByVal Value As Object)
Debug.WriteLine ("'Test(Foo) '")
End Set
End Property
..
..
..
Test(1) = 1
Test(Foo.Baz) = 1
///

Output:

---
'Test(Integer)'
'Test(Foo)'
---

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
I found that the information is indeed a bug, but then in the VB language. An excellent
explanation can be found on Rob Gruen's weblog:
http://weblogs.asp.net/robgruen/arch.../26/97104.aspx

There is also an extensive discussion on this issue on dotnet247.com:
http://www.dotnet247.com/247referenc...56/284220.aspx
"Arnold Schrijver" <ar************ *************@2 organize.com> wrote in message
news:e1******** *******@TK2MSFT NGP09.phx.gbl.. .
Hi,

Given your code, I could reproduce the strange behavior again! I added the VB project
in the attached zip-file.

With your code in Class1 these calls:

Dim objTest As New Class1

objTest.Test(0) = "0 Integer"
objTest.Test(1) = "1 Integer"
objTest.Test(Cl ass1.Foo.Goo) = "0 Enum"
objTest.Test(Cl ass1.Foo.Baz) = "1 Enum"

Result in:

'Test(Foo)'
'Test(Integer)'
'Test(Foo)'
'Test(Foo)'

I am using Visual Studio 2003 (v. 7.1.3088) with .NET Framework 1.1 (v. 1.1.4322 SP1)
on Windows 2000 SP4 (v. 5.00.2195)

As a temporary workaround to fix the code I appended a dummy Boolean to the overloaded
enum Method, to create a method signature that differs more significantly. This works, but is
not pretty.

Thanks for your response!

Cheers,

Arnold.

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:e8******** ********@TK2MSF TNGP09.phx.gbl. ..

<SNIP/>
Nov 21 '05 #3
"Arnold Schrijver" <ar************ *************@2 organize.com> schrieb:
I found that the information is indeed a bug, but then in the VB language.
An excellent
explanation can be found on Rob Gruen's weblog:
http://weblogs.asp.net/robgruen/arch.../26/97104.aspx

There is also an extensive discussion on this issue on dotnet247.com:
http://www.dotnet247.com/247referenc...56/284220.aspx


Thank you for sharing these interesting links. In the meantime I was able
to repro the behavior in VB.NET 2002 too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
3466
by: Dmitriy Iassenev | last post by:
hi, I found an interesting thing in operator behaviour in C++ : int i=1; printf("%d",i++ + i++); I think the value of the expression "i++ + i++" _must_ be 3, but all the compilers I tested print 2.
5
6893
by: Andy Jarrell | last post by:
I'm trying to inherit from a specific class that has an overloaded operator. The problem I'm getting is that certain overloaded operators don't seem to come with the inheritance. For example: // TestA.h --------------------------------------- #include <iostream> enum Aval { FIRST_VALUE,
6
2560
by: Mårten Herberthson | last post by:
Introduction: As we all know, values of any class may be assigned to a reference of a superclass. This is simple polymorphism. So if you have a class A and a class B that inherits from A you can write a method that returns an instance of B and assign that to a reference of type A. (Trivial) Problem:
9
1661
by: Karahan Celikel | last post by:
Here are three simple classes: class A { public void DoIt(B b) { DoSomething(b); } public void DoSomething(B b) {
0
1509
by: student | last post by:
In Summary: Create an object - dont set one of its Enum Type properties and make sure it does not appear in XML Object Serialization. Strings function as hoped for but Enums do not Heres my problem broken down to simplest form I have the following ENUM ----------------------------------------------
6
2284
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to the same method (aka delegate?). I use the Tag property within this method to determine what user action is taking place. Very simple: When adding toolbar button: tbButton.Click += new...
4
4043
by: Pritcham | last post by:
Hi all I've got a number of classes already developed (basic entity classes) like the following: Public Class Contact Private _firstname as String Private _age as Integer Public Property FirstName As String
1
2982
by: Nicholas Palmer | last post by:
Hi all, Got a question about the AspCompat=true page property. First a little background. We have an ASP.NET app that uses two COM components. The first is the Microsoft OWC 11 components and the second is a custom VB6 COM component. So I was reading about AspCompat=true and it seemed like it would be a good fit for our app. From what I can tell both of the COM components that we are using are STA and we are creating the components in...
2
3524
by: JB | last post by:
Hi All, I'm pulling my hair over this and could really do with a bit of help. I'm using various different enums as bit fields and I'd like to create a set of generic Functions or Subs to manipulate the bitfields. For instance: <Flags()_ Enum ActionFlags As Byte
0
9861
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10605
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10301
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9444
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7839
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7023
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.