I need to support both API1.0 and 2.0 (like most of the rest of us)
So I started to create a module that had a number of EXTENDS
for example
Public Sub API2_DrawingColor1(extends g as Graphics, assigns clr as color)
// Xojo2019r2 : API2.0 compatiblity code
#If XojoVersion >= 2019.02 Then
g.DrawingColor=clr
#Else
g.ForeColor=clr
#EndIf
End Sub
But I am trying to figure out how to extend things that are not attributes of an existing class
Like UBOUND
Private Function API2_LastRowIndex( ????? ) as integer
// Xojo2019r2 : API2.0 compatiblity code
#If XojoVersion >= 2019.02 Then
Return ??????.LastRowIndex
#Else
Return ?????.Ubound
#EndIf
End Function
Seems nobody understands the question I asked.
I donât want to extend myClass⊠I have an ARRAY (donât care what datatype it is)
All I want it the UBOUND/LastRowIndex⊠in a manner that is API1 / API2 âsafeâ
youâd need to extend whatever the data of that array is
and you can only do a single dimnesion array
Private Function API2_LastRowIndex( extends stringArray() as string ) as integer
// Xojo2019r2 : API2.0 compatiblity code
#If XojoVersion >= 2019.02 Then
Return stringArray.LastRowIndex
#Else
Return stringArray.Ubound
#EndIf
End Function
Private Function UboundGeneric(extends objectArray() as Object) as Integer
#if XojoVersion >= 2019.02 then
Return objectArray.LastRowIndex
#else
Return objectArray.Ubound
#endif
End Function
Hereâs my test harness code
[code]dim a() as Class1
for intCycle as Integer = 1 to 100
a.Append( new Class1 )
next
dim x as Integer = UboundGeneric( a )
break[/code]
Public Function API2_LastRowIndex(extends objectArray() as Object) as integer
#If XojoVersion >= 2019.02 Then
Return objectArray.LastRowIndex
#Else
Return objectArray.Ubound
#endif
End Function
I also coded a method for storage types. Itâs quite a bit of code, but it gets the job done the best it can be in Xojo as-is, I believe. If someone comes up with something better, Iâd love to take a look.
See âUsageâ note in API2Compat module for more info. This module is provided free for personal or commercial use.
Here are the routines I have for handling object Arrays across the API versions
(Thanks Anthony for the right direction to head)
Public Sub API2_AddRow(extends objectArray() as object, item as object)
// Xojo2019r2 : API2.0 compatiblity code
#If XojoVersion >= 2019.02 Then
objectArray.AddRow item
#Else
objectArray.Append item
#EndIf
End Sub
Public Sub API2_AddRowAt(extends objectArray() as object, index as integer, item as object)
// Xojo2019r2 : API2.0 compatiblity code
#If XojoVersion >= 2019.02 Then
objectArray.AddRowAt index,item
#Else
objectArray.Insert index,item
#EndIf
End Sub
Public Function API2_LastRowIndex(extends objectArray() as Object) as integer
#If XojoVersion >= 2019.02 Then
Return objectArray.LastRowIndex
#Else
Return objectArray.Ubound
#endif
End Function
Public Sub API2_RemoveRowAt(extends objectArray() as object, index as integer)
// Xojo2019r2 : API2.0 compatiblity code
#If XojoVersion >= 2019.02 Then
objectArray.RemoveRowAt(index)
#Else
objectArray.Remove(index)
#EndIf
End Sub
This allowed me to write code using 2019r1.1, that is compatible (no deprecation warnings) in 2019r2
and should I decided to go full blown R2 then I just dump the module that contains the above code, and remove all the âAPI2_â tags, a 2 minute operation at best
I did not post them here, but I did a similar thing for most of the graphics routines as well
Just one example :
Public Sub API2_DrawText(extends g As graphics, str As String, x As Double, y As Double, width As Double = 0, condense As Boolean = False)
// Xojo2019r2 : API2.0 compatiblity code
#If XojoVersion >= 2019.02 Then
g.DrawText(Str, x , y, width, condense)
#Else
g.DrawString(Str, x , y, width, condense)
#EndIf
End Sub