64 Bit and Variant

I stumbled upon an issue while making my app 64-bit (on OS X, Windows). Since Integer is int32 on 32-bit systems and int64 on 64-bit systems it seams that XOJO has forgotten to change that on VarType and variants.

It took some time to find bugs caused by the fact that the constant Variant.TypeInteger is 2 on 32 and 64-bit systems. The documentation says exactly that:

Because of this, the following code shows the message “Integer” on 32-bit systems and “Other” on 64-bit systems.

[code]Dim v As Variant

v=5

If v.Type=Variant.TypeInteger Then
MsgBox “Integer”
Else
MsgBox “Other”
End If[/code]

You have to change the code that it will work on both 32 and 64-bit systems:

[code]Dim v As Variant

v=5

If v.Type=Variant.TypeInt32 Or v.Type=Variant.TypeInt64 Then
MsgBox “Integer”
Else
MsgBox “Other”
End If[/code]

I think this is inconsistent and if XOJO changes the constant to 2 (TypeInt32) on 32-Bit systems and 3 (TypeInt64) on 64-bit systems, old code would just work and nobody would have issues with that.

sounds like TypeInteger should be 3 on 64-bit and 2 on 32-bit?

That would be great.

With the release of 2017r2 and improved 64 bit, this becomes even more topical. Should TypeInteger either be removed or updated to avoid hard to find bugs for people transitioning to 64 bit? I know that variant will eventually be phased out with the new framework, but that won’t be for a while (hopefully).

TypeInteger is still valid - if you use

dim i as integer
dim v as variant = i

then its still a “TypeInteger”

But comparisons don’t work. When compiling for 64bit I had to change all “Variant.Type = Variant.TypeInteger” to “Variant.Type = Variant.TypeInt32 or Variant.Type = Variant.TypeInt64”. Bug, feature or misunderstanding?

I’m not in front of my computer at the moment. But I’ll have a look at the code in the afternoon.

In the docs it is clearly stated that .TypeInteger is being replaced by .TypeInt32 (I assume this happened on the introduction of Int64 as a data type many years ago). So I think its behavior should not be changed. Actually in my view they should have deprecated it with the introduction of .TypeInt32.

I would expect Variant.TypeInt64 = Variant.TypeInteger for 64bit as Integer is just an alias to Int32/Int64 depending on bit depth.

Well this one just bit me. An old 32-bit app I wanted to update uses lots of list Rowtags as Variants and checks the VarType to see if an integer is stored there. Being able to check for Int32 or Int64 is fine. It would be nice to be able to check for generic “integer”, with one VarType code for “integer” that would work in both 32 and 64 bit builds. Having to change all these VarType comparisons for the sake of 64 bit building is annoying and the bugs this has produced led me in all kinds of wrong directions and wasted a lot of time.