Skip to content

Converting Code to API 2.0

Xojo 2019r2 has many changes related to API 2.0. Most of your projects should open and run without any changes. You can then switch code to API 2.0 when you want (or not at all — it’s up to you).

General Tips

With that said, here are a few things that you may have to update to be able to run your project using 2019r2 and later Xojo releases:

  • Some advanced properties on FolderItem have been removed.
  • You’ll have to use the Global prefix with the ToolTip class (or switch to new methods).
  • You’ll have to add the new EndOfFile method to anything that uses the Readable interface.

Converting Code to Use a New Class

When converting code to use a new class that replaces a deprecated one, there are two different approaches that will help you do so efficiently.

Method 1: Not Familiar with the New Class

When you’re not familiar with the new class, replace class members such as properties and methods first, before replacing the class declaration itself. This will allow you to use auto-complete to see which methods or properties replace the deprecated ones.

Consider the following code example:

Dim rs as RecordSet
rs =db.SQLSelect(“SELECT * FROM Customers”)
If rs <> nil then
While Not rs.EOF
//perform some data processing
  rs.MoveNext
Wend
End If

Deleting EOF and then pressing tab will display the auto-complete menu showing the replacement method, AfterLastRow:

Auto-complete will not replace EOF with AfterLastRow as the variable rs is still a RecordSet. However, you can manually make the change now. Once you have changed all class member references, you can then change the variable itself from RecordSet to RowSet.

Method 2: Familiar with the New Class

If you are familiar with the new class, change the variable (rs in this case). Having done so, you can use auto-complete to change any class members references (properties, methods, etc.) to the new class.

In the beginning the changes in API 2.0 will be unfamiliar so Method 1 above will make sense. Over time you’ll be more familiar with API 2.0 and then Method 2 will work best. The important thing is to remember that you can do this at your own pace. The APIs that have been replaced will continue to be available for a very long time.

Summary

These changes and more are described in detail in the API 2.0 Guidelines topic in the docs. Be sure to give it a quick read to more easily get up and running with 2019r2. For other guidance on moving projects to API 2.0 to take advantage of newer features and improved naming (again, when you’re ready), be sure to read Moving to API 2.0.