New Posts New Posts RSS Feed: Testing for enums
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Testing for enums

 Post Reply Post Reply
Author
brianlj View Drop Down
Newbie
Newbie
Avatar

Joined: 03-Jul-2007
Location: United States
Posts: 8
Post Options Post Options   Quote brianlj Quote  Post ReplyReply Direct Link To This Post Topic: Testing for enums
    Posted: 08-Aug-2007 at 8:46am
Hi -
I have some problems when I try to test the value of an enum in code.  For example, I use:
 
If testentity.status Is testentitystatus.Ready then
.....
end if
 
This seems to work MOST of the time, but inexplicably fails to return TRUE at times (when I know the status is READY).
 
Any thoughts?  Should I be testing differently?
Thanks!
Back to Top
Linguinut View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 394
Post Options Post Options   Quote Linguinut Quote  Post ReplyReply Direct Link To This Post Posted: 08-Aug-2007 at 12:55pm
Hi Brian,
 
Have you put a break on that line to see what the actual values are for each of the test subjects?  testentity.status must be returning something other than testentitystatus.Ready for it to return false.  I state the obvious.  Perhaps you can trace back from the breakpoint why the status property has not changed by that point in the code.
 
Bill
Back to Top
wdevine View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 5
Post Options Post Options   Quote wdevine Quote  Post ReplyReply Direct Link To This Post Posted: 08-Aug-2007 at 3:22pm
My VB.NET isn't as polished as it should be, but I think I'd use something like this:
 
If testentity.status = testentitystatus.Ready then
 
I'm not 100% sure, but I think the 'Is' operator in the context that it is being used is and object compare.
 
Bill 
 
 
 
Back to Top
brianlj View Drop Down
Newbie
Newbie
Avatar

Joined: 03-Jul-2007
Location: United States
Posts: 8
Post Options Post Options   Quote brianlj Quote  Post ReplyReply Direct Link To This Post Posted: 09-Aug-2007 at 10:21am
Yes, you are correct that 'Is' does a literal object compare.  But since DevForce uses cached objects, my thought is they should be one in the same object.  And this seems to be true MOST of the time, but I have had bugs that I have traced back to this compare failing.  And unfortunately, I don't believe there is an operator overload for '='; I could probably write my own, but was trying to avoid doing this for every enum.
 
I have of course debugged and made sure the status is what I expect. 
Back to Top
jsmark View Drop Down
Newbie
Newbie
Avatar

Joined: 22-Jun-2007
Location: Canada
Posts: 3
Post Options Post Options   Quote jsmark Quote  Post ReplyReply Direct Link To This Post Posted: 09-Aug-2007 at 1:29pm
Try doing something like testentity.Status.ID  = testentitystatus.Ready.ID
(ID being the identity field in the database)
Back to Top
brianlj View Drop Down
Newbie
Newbie
Avatar

Joined: 03-Jul-2007
Location: United States
Posts: 8
Post Options Post Options   Quote brianlj Quote  Post ReplyReply Direct Link To This Post Posted: 09-Aug-2007 at 6:29pm
testentity.Status.ID  = testentitystatus.Ready.ID is what I ended up doing and I believe should work just fine.  However, it would be nice if you could just compare the enum entities directly and not have to know the specific fields when trying to compare. I know, I know..... in a perfect world......just seems like DevForce should have all the info it needs to support this functionality.......
 
Thanks to all that provided some input here......
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down