Compat flags

What are these things and what use do they have ?

Buried away on the advanced tab of the inspector for most things is a little section that has a lot of check boxes labelled Desktop, Web, Console, iOS that I’m sure most folks dont know what they are for or what you’d use them for.

For your own code these can be immensely useful. If you happen to want to share code between project of different kids then you may need to use these.

What they let you do is create classes or code that can have different implementations depending on what kind of project the code is in.

For instance suppose you have a library of code you were working on, your own “framework” for an app that had aspects that ran on all targets.

You might create a module for your framework code. And in there it could have several implementations of your crucial method, Foo() – one for each of console, web desktop and even iOS as follows

Public Sub Foo(param as string)
  MsgBox "desktop foo !"  
End Sub
Public Sub Foo(param as string)
  MsgBox "Web foo !"
End Sub
Public Sub Foo(param as string)
  MsgBox "Console foo !"  
End Sub
Public Sub Foo(param as Text)
  Dim helloMessage As New iOSMessageBox
  HelloMessage.Title = "Hello"
  HelloMessage.Message = "iOS foo !"
  HelloMessage.Show // Not modal, so code does not pause here
End Sub

Yeah I realize its not sophisticated. Thats not the point. Maybe this ias a method that you have for calculating some vital function for your app. Or for fetching some data from a web service.

The compatibility flags for each of these would be set differently. The one that sayd “Desktop foo” should be marked for desktop only

The web one would be marked for web only

And similarly for the iOS and Console one

So now we have this handy dandy super module with all kinds of functionality in it that …

yeah … this is an example OK ?

I have my module set up in a desktop application and if, in Window1.Open I put


Guess which method gets executed ?

If you guessed the one marked compatible with desktop apps then you’re quite right.

And if we take this handy dandy module and copy & paste it into a Console app, guess which one runs ?


And even iOS

Thats all well and good but whats going on ?

Is all this magic happening at runtime and all the code is in the app all the time ?

Not at all.

The IDE, at compile time, selects the compatible version of the methods to compile depending on how the compatibility flags are set. And it only compiles those.

So despite our handy dandy module having all those different versions in it only the desktop ones will get compiled in a desktop app, only the web ones in the web app, and so on.

I hope you can make good use of this !