Hello,
How can i exclude for windows-os class other os on ide ?
Ty
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.
like Greg said, but you canât decide between windows and macos (or linux) with these
Thereâs no technical reason why excluding by platform canât be done. Itâs just not available in the IDE.
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.
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.
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.
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.