I’m creating a module to help me to start my migration from my xojo 2018 web project to 2021 version.
so, i’m “extending” some object methods. for example:
on 2018 project, i did:
Public Sub RemoveAllRows(extends lbx as WebListBox)
lbx.DeleteAllRows
End Sub
So i can change all my 2018’s bx.DeleteAllRows to lbx.RemoveAllRows
Then, when i open on my 2021 xojo ide, all will be ready!
But, how can i use or ignore this method depending on xojo’s version?
How can i use the actual “lbx.RemoveAllRows” for the 2021 version, instead of calling my own method?
Another example…
Public Sub MessageBox(myMessage as string) #if XojoVersionString=“2018r1.1” then
MsgBox(myMessage)
else
MessageBox(myMessage) #endif
End Sub
How to use MY METHOD for 2018 version, and XOJO’S METHOD for 2021 version?
if i use my messagebox with an “else” to call xojo MessageBox, it’ll give me a stack overflow
You should be able to use the explicit namespace to solve this issue, but I’m not sure if that’s possible with some calls.
E.g. something like this:
Public Sub MessageBox(myMessage as string)
#if XojoVersionString=“2018r1.1” then
MsgBox(myMessage)
else
Xojo.MessageBox(myMessage) // call the built-in framework version, rather than this override method
#endif
End Sub
Public Function CellValueAt(extends lbx as WebListBox, Row as integer, Column as integer) as string #if XojoVersionString=“2018r1.1” then
return lbx.Cell(row,column) #else
return Xojo…??? #endif
End Function
@Alexandre_Cunha please remember to use the Preformated Text button for source code (it looks like this in the forum): so your code will be nicely formatted.
I’m not sure what you want to do is possible - the documenation says:
Methods declared in this way are sometimes called “class extension methods” even though they are not actually part of a class. You can use Extends only for methods in a module. Extends cannot be used to override another method. Extension methods are not virtual, since they are not part of a class.