Session - enumerations

In a webapp I log which platform the user is running. I tested the Platform property of the session object.
According to the documentation, Websession I should have the following enums:

0 Unknown
1 Macintosh
2 Windows
3 Linux
4 Wii
5 PS3
6 iPhone
7 iPodTouch
8 iPad
9 Blackberry
10 WebOS
11 AndroidTablet
12 AndroidPhone

I tested: Windows (2) , Linux (3) , iPhone (6) and iPad (10).
iPad should be 8. (???)

The docs don’t specify values. They are enums. Compare them against WebSession.PlatformType.xxx

Which directs me back to the list above Websession .
Think the issue with the documentation is that the values should have been listed, and second the value for iPad seems to be the same as WebOS, which should be reported as a bug.
@Greg O’Lone - I know that this is not the biggest thing but even small things should be reported.
I was just challenging somebody else to repeat the test for me before reporting it to FB.

It’s been corrected on the online docs, but the point of an enum is so you don’t need to know the values. Use them and it’ll work just fine.

There is no “second value” for iPad. The order was a little off, but nothing has been duplicated.

[quote=122110:@Joost Rongen]In a webapp I log which platform the user is running. I tested the Platform property of the session object.
According to the documentation, Websession I should have the following enums:

0 Unknown
1 Macintosh
2 Windows
3 Linux
4 Wii
5 PS3
6 iPhone
7 iPodTouch
8 iPad
9 Blackberry
10 WebOS
11 AndroidTablet
12 AndroidPhone

I tested: Windows (2) , Linux (3) , iPhone (6) and iPad (10).
iPad should be 8. (???)[/quote]

Don’t count on the integer value being any specific value
Thats the point of the enumeration - you use the symbolic value not the integer

If your code reads like

If Session.Platform = 8 then end if

Then if, for some odd reason, we do have to change the enumeration this code breaks - silently.

If your code reads like

If Session.Platform = WebSession.PlatformType.iPhone then end if

this code won’t break even if the enumeration changes so that iPhone is now value 2 instead of 8

My apologize @Norman Palardy , your are right, of course this is the definition of enum. And my apologize to @Greg O’Lone too, since I’ve tested it using the enums this way it works fine.
In my app I wanted to log just the integervalue in the database straight from the session and that didn’t work as expected for iPad, while it did for all others.
If you guys where @Dana Brown I would have send “poffertjes” now. :slight_smile:

To put the value in the DB you do end up putting the numeric in the DB since it can’t represent it any other way

BUT when you grab it from the DB you can convert it back into the enum with a cast with something like

dim myProp as WebSession.PlatformType = WebSession.PlatformType(recordset.idxField(X).IntegerValue)
If myProp =  WebSession.PlatformType.iPhone then
end if

Even if you don’t do this you COULD do

select case recordset.idxField(X).IntegerValue
case WebSession.PlatformType.iPhone 
case WebSession.PlatformType.iPad
…. etc ….
end select

[quote=122540:@Norman Palardy]To put the value in the DB you do end up putting the numeric in the DB since it can’t represent it any other way

BUT when you grab it from the DB you can convert it back into the enum with a cast with something like

dim myProp as WebSession.PlatformType = WebSession.PlatformType(recordset.idxField(X).IntegerValue)
If myProp =  WebSession.PlatformType.iPhone then
end if

Even if you don’t do this you COULD do

select case recordset.idxField(X).IntegerValue case WebSession.PlatformType.iPhone case WebSession.PlatformType.iPad …. etc …. end select [/quote]
Hi Norman, I think you’ve just contradicted yourself a little here, as if you store the integer value of PlatformType while using Xojo 2014r2 and then Xojo 2015r3 for some odd reason changes the enums, when you rebuild a version of your app with the later version it will report the wrong platform when doing any historical analysis.

It seems safer to store a string representation of the platform type, e.g. “iPhone”, “iPad” etc.

In retrospect, I think that we should consider the usage of reporting tools by the user, which pleads for putting name as string or a reference to another table containing all the possible names.

[quote=122760:@Ian Jones]Hi Norman, I think you’ve just contradicted yourself a little here, as if you store the integer value of PlatformType while using Xojo 2014r2 and then Xojo 2015r3 for some odd reason changes the enums, when you rebuild a version of your app with the later version it will report the wrong platform when doing any historical analysis.

It seems safer to store a string representation of the platform type, e.g. “iPhone”, “iPad” etc.[/quote]
You could you just don’t have a simple way to get from the enumerated value to the matching string

If you need to reverse it, then I guess a simple little function that maps the enums to strings as there’s no introspection would do it. You’d just have to update it whenever you update Xojo and notice that a mapping fails.