Bypass extends method


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)
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
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

Thank you all!

When you use the new Xojo version you delete the module from the project.

yep, but i want to do this gradually, so i want to run on 2018, and just check if it’s all ok on 2021.

i want to execute on 2021, and during the tests, i’ll implement the “upgrades” on my module. then back to 2018, check, go to 2021, check…

Compatibility Flags

you can indicate something should only be available for versions prior to 2019r2 by checking the API 1 flag.

Note: Compatibility flags are shown on the Advanced tab of the Inspector.

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
  Xojo.MessageBox(myMessage)  // call the built-in framework version, rather than this override method
End Sub

However, the documentation does not say whether this is possible:


there is no copatibility flags on 2018…


for messageBox worked just fine!

and for this one?

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)
return Xojo…???
End Function

@Alexandre_Cunha please remember to use the Preformated Text button for source code (it looks like this in the forum): image 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.

Edit: indeed, if you try to Extend an existing class method, it fails:

Public Function Len(extends s as String) as integer
  return s.Len
End Function