Exclude Class

Hello,

How can i exclude for windows-os class other os on ide ?

Ty

There’s no way to exclude on a class-by-class basis. You’ll have to design your code so that the Windows-only classes can be encapsulated like this:

#If TargetWindows Then
    //Windows-only code
#EndIf

The code inside the #If-#EndIf will only be included in Windows builds.

Can you share more details on what your situation looks like? There are multiple ways to accomplish what you’re trying but deciding between them is tricky without more context.

It should be noted that you can do this for the different project types however. If you select your class in the navigator and then go to the advanced tab on the inspector, there’s a list of items in the Include In section which you can use to control whether or not the item is included in a particular project type.

1 Like

like Greg said, but you can’t decide between windows and macos (or linux) with these

Capture d’écran 2024-09-30 à 23.32.43

There’s no technical reason why excluding by platform can’t be done. It’s just not available in the IDE.

1 Like

The way to “exclude” classes from any build is to not reference them in code. If you have a class Win64Button, for example, you can’t have a property myButton as Win64Button; you can’t put one on a window layout; you can’t refer to a static class constant like Wn64Button.kDefaultCaption; etc etc etc. The linker/compiler automatically includes any referenced class in your build.

There are several quite effective techniques to deal with this. Take, for example, the Win64Button class. It contains several Windows-specific pieces of code that make it look like a Windows button. If you are building your app for other platforms, you can do this:

Event Paint(g as Graphics)
   #If TargetWindows Then
        //Windows drawing code
    #ElseIf TargetMacOS
        //Mac drawing code
    #ElseIf TargetLinux
        //Linux drawing code
    #EndIf
End

This is how you can do platform-specific Declares:

#If TargetWindows Then
    Declare Function GetClassLong Lib "user32" Alias "GetClassLongA" ()

    myClassLong = GetClassLong()
#EndIf

This will compile on all platforms, even though the declare is only available in Windows.

You can also leverage the power of Xojo’s class inheritance structure:

Class MyButton

Class Win64Button Inherits MyButton
Class MacButton Inherits MyButton
Class LinuxButton Inherits MyButton


which lets you have a property MyButton on, for example, a window. Each MyButton subclass contains platform-specific code (and the base class can contain all the platform-agnostic code). Then, when you need to create the object, you would do:

Class MyButton
Static Function GenerateInstance() as MyButton
   #If TargetWindows Then
        Return New Win64Button
    #ElseIf TargetMacOS
        Return New MacButton
    #ElseIf TargetLinux
        Return New LinuxButton
    #EndIf
End

Even though the code references Win64Button, because it is inside the #If 
 #EndIf block, it will get stripped out of builds for other platforms.

That’s something I would love to have. I’ll open a feature request.

Edit: the IDE does not allow me doing the thing I wanted. Same class name, different code, targeting different OS. So currently there are limitations. FR aborted for now.
I would also like to mark some windows with the same name but targeting different OSs so the built system could work seamlessly but with a very distinct UI for each OS.

I believe one already exists. If I recall correctly, the reason it doesn’t exist is in the complexity of the UI. I think what we expect is a handful of new checkboxes, but there are more exotic combinations that require a more complex interface. For example, maybe you need Mac and Windows desktop, but Linux Web. I can’t think of a good reason why you would, but I remember this complexity is why the choices are not more robust.

What’s funny to me is that platform-specific classes are more useful than project-specific classes, simply because of how much Xojo projects suck at code sharing.

2 Likes

Surely the interface change is simple, replace the desktop line with the three OSs:

MacOS x 32 bit x 64 bit
Windows x 32 bit x 64 bit
Linux x 32 bit x 64 bit

I believe the feature is called “compatibility flags” within Xojo.

1 Like

But it will take a lot of brainstorming and IDE changes from Xojo to make it work as we expect, as I said and Thom confirmed. You should create Class1 and mark it macOS 64, and another Class1, same name, and mark it Windows 64. You should click somewhere to say “IDE Target mode: macOS” and autocomplete, for instance, should autocomplete for your target only. The compiler should see just your target too and never complain “Class1 already exists”. Or Window1 already exists if they have different OS targets. All those things.
Rick, can it be done? Sure.
Would be great? Sure.
Do you see it done anytime soon by Xojo? No. Not soon.

The “easiest” solution is to give us the checkboxes we have now, but also let us write code. Because that’s all the IDE is doing. If you’ve ever looked inside a version control project, it’s just code like CompatibilityFlags = ( TargetDesktop and ( Target32Bit or Target64Bit ) ). So in theory, if we can write our own code, we could use our own constants too.

1 Like

I’m pretty sure we’ve been there before, with asking for a fully editable compatibility flags option, and it was turned down.

The check boxes would suffice for most purposes.

Without an IDE dynamic “behave as if you were working in the target X”, things as autocomplete should be disabled or “mixed” when overlapping, causing a bit of confusion in some cases. And only presenting real errors when compiling, like obj1.func34() does not exist when targeting macOS, but it exists for Windows. func34() should autocomplete for macOS, but should not for Windows(), cmd-K should warn us anyway. obj1 is from Class1, and Class1 exists twice, one for macOS and one for Windows, and they differ.