Cs0266

Zenerdiode

Active Member
Licensed User
I am getting a CS0266 compiler error when compiling the following line:

B4X:
Sub Globals
   'Declare the global variables here.
   Dim Binary(0) As Byte

End Sub

Sub App_Start
   Reg.New1 'Reg is a RegistryDesktop object
   Reg.RootKey(Reg.rtCurrentUser)
   Binary()=Reg.GetValue("Control Panel\Desktop","UserPreferencesMask") 'Causing the CS0266 error
   '....
End Sub

I may be wrong, but I think Reg.GetValue is trying to return an object that I'm then trying to assign to the array - but that is the method shown in the Registry library help.

It works fine in the IDE; but when compiling to Desktop it return the compiler error. Could someone suggest a fix to the RegistryDesktop.cs file for me please?
 

Zenerdiode

Active Member
Licensed User
Thank You - that has helped for getting a Byte array; however .GetValue is also used for returning an array of strings - in the case of a hive being a 'REG_MULTI_SZ'

I still need a solution/update to RegistryDesktop.dll
 

mjcoon

Well-Known Member
Licensed User
Thank You - that has helped for getting a Byte array; however .GetValue is also used for returning an array of strings - in the case of a hive being a 'REG_MULTI_SZ'

I still need a solution/update to RegistryDesktop.dll

Is your complaint really that the Help for Registry.dll is a bit faulty? After all, there is a GetStringsArray() method. And a GetValueKind() for finding out which Get... method (and hence which variable) to use for each entry.

So the problem is perhaps that GetValue can be used in the old flexible variable manner for non-array values that do not have to have a fixed declared type. But not, despite what the Help says, for arrays...

Mike.
 

agraham

Expert
Licensed User
Longtime User
I am getting a CS0266 compiler ... It works fine in the IDE; but when compiling to Desktop it return the compiler error. Could someone suggest a fix to the RegistryDesktop.cs file for me please?
I suspect that RegistryDesktop predates the optimising compiler and there isn't a simple mod for the C# code as it doesn't know the type of data. The underlying problem is that you can assign any just about anything (even an array) to a single variable of type Object as that is an automatic downcast but you can't assign an array of Object to an array of anything else without an explicit cast as that is an upcast.

The best solution is, as suggested by Mike, to use GetBytesArray as you already know the type of the return that you want. You could also assign GetValue to a Door library Object (not an ObjectArray as that will error for the reason given above) and play with it using reflection
B4X:
Obj1.New1(False)
Obj1.Value = Reg.GetValue("Control Panel\Desktop","UserPreferencesMask")
v = Obj1.RunMethod2("GetValue", 0, "System.Int32")
Msgbox(Obj1.RunMethod("ToString"), v)
 

mjcoon

Well-Known Member
Licensed User
The underlying problem is that you can assign any just about anything (even an array) to a single variable of type Object as that is an automatic downcast but you can't assign an array of Object to an array of anything else without an explicit cast as that is an upcast.

As far as that's concerned I'm just an outcast!

Mike.
 
Top