How to make object properties backwards compatible?

If you have a property theConnection as URLconnection (introduced in Xojo 2018 R4) but you need the code to be compatible with older versions, then what is the recommended way of doing it?

After all you can’t make the type conditional as far as I know, and making it a variant requires casting everywhere. Is there a more elegant way of doing it?

1 Like

welcome to the hell that API 2 brings

you could try setting those properties compatibility flags OFF saving and seeing if the older versions preserve that (and obey it)
but then your users have to be aware of how to turn that back on at some point

the other option is
https://www.great-white-software.com/blog/2019/10/11/maintaining-backwards-compatibility-in-2019r2/

they all suck

1 Like

If it’s only URLConnection you are worried about, I would suggest a wrapper class .

Under the hood used HTTPSecureSocket or URLConnenction using #If XojoVersion in code. That way it could compile or run in any Xojo version.

-Karen

1 Like

you still cant define a property unless its a variant :frowning:
its a mess Xojo could have avoided but didnt

HA! Have been out looking at houses all day (Auckland is a nightmare) and on the way back thought about a wrapper … seems I do make some progress after all … :nerd_face:

If you have the MBS plugins use CURLSMBS instead as it works so much better.

1 Like

A wrapper is not a general solution for properties… in this case it is about creating a class with a potentially unique API (or one that matches either class) that translates the properties as needed under the hood to use either URLConnection or HTPPSecureSocket to make it Xojo version agnostic.

-Karen