Using #

Quick question about using the Pound ("#") symbol. If I want one thing to happen on Windows and something else to happen on OS X and I want the Windows Code to only be in the Windows build and the OS X code to only be in the OS X build, can I do this:?

#If TargetWin32 then Run Windows code #ElseIf Run OS X code #EndIf
or do I have to do it this way?

[code]#If TargetWin32 then
Run Windows Code

#If TargetOSX then
Run OS X Code

Just wondering what the best code practice is?

It’s up to you since these would do the same thing. I like the former.

Thanks. I was just wondering since this is my first time using this type of conditional. I’m used to the regular If…Then Statements.

This form tells the compiler what to include or exclude while compiling. The code that is excluded simply doesn’t make it into the final app.

Is there a way to have a specific Function to only be compiled into the Windows Build? I need to have DoubleBuffer and Transparency in Windows and I have a Function that simulates Transparency but I only need it in the Windows Build.

When you select a method, in the inspector choose the advanced tab, represented by the gear icon. You can then turn off platforms, which will do what you’re looking for.

Thanks. Much has changed since I started using RealBasic over 10 years ago. I started on version 5 or so.

I just checked and I don’t see a way to Exclude Mac OS X. I only see options for Desktop, Web, Console and iOS.

Sorry, that’s a good point, I forgot about that. You could file a feature request for it, I know it is possible.

Wrap your function in the #If TargetWin32 conditional If block. The code in that function will only be compiled for Windows. Or put every call to the function inside a conditional If block. Same difference.

I was already doing the latter as I need something different to happen in Mac OS X which never calls this function as it already DoubleBuffers with Transparency natively so there is no need to simulate the Transparency.