We use a VO created function Array2String which returns an array as a delimiter separated string. In a specific situation, the array was empty which returns an empty string in VO, but apparently a nil value in X#.
I know that in .Net we are supposed to initialize all variables but in this case the compiler did not warn; by adding the 2 bold lines it works fine again. Should the compiler warn that I might return an uninitialized variable? The function does not return a proper empty string either.
Is this expected, or something we can prevent somehow? I can imagine that a lot of converted code with uninitialized variables would work in VO but not in X# as I found today.
Below the function
Dick
[hr]
Function Array2String( aArray As Array, cSep As String ) As String
Local cString As String
Local nMax, i As Dword
nMax := ALen( aArray )
For i := 1 Upto nMax
cString := cString + AsString( aArray[ i ] ) + cSep
Next i
If SLen( cString) > 0
cString := Left( cString, SLen( cString ) - 1 )
Else
cString:="" // 23-12-2021 Otherwise cString does not return the right value
Endif
Return cString
Returnvalue of uninitialized variables
Returnvalue of uninitialized variables
Hi Dick,
Please enable the compiler option /vo2 ("Initialize Strings" in the Dialect page of the Project properties in VS) and it will auto initialize string vars and iVars. This option is enabled by default in all apps ported from VO (with XPorter).
Please enable the compiler option /vo2 ("Initialize Strings" in the Dialect page of the Project properties in VS) and it will auto initialize string vars and iVars. This option is enabled by default in all apps ported from VO (with XPorter).
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
Returnvalue of uninitialized variables
Hello Chris,
I knew something was arranged for this Sounds good!
The issue occurred in the X#/C# lib we use from VO, so this was not a converted program.
Dick
I knew something was arranged for this Sounds good!
The issue occurred in the X#/C# lib we use from VO, so this was not a converted program.
Dick