Compiler Directives


As you can see, there are a lot of differences between the platforms, and despite how well REALbasic has done at making cross-platform application development easy to do, you will undoubtedly find yourself writing code for specific platforms. Fortunately, you do not have to maintain separate projects for each platform. Instead, REALbasic provides some compiler directives that allow you to tell the compiler which lines of code should be compiled for which platform.

Compile directives can be used in any part of your code, and they are always wrapped in a special kind of If...Then statement, one that starts with a # character. Here's an example:

#if TargetWin32 then // Do something unique to Windows #elseif TargetMacOS then // Do something Mac-like #else // Do it for Linux #endif 


I have a real-life example of how you would use this later on in this chapter. This ends up being extremely helpful because you are able to leverage some of the unique qualities of each platform and provide a more platform-specific feel to the application than you would otherwise. Several compiler directives can be used, offering you fine-grained control over managing your code:

TargetMacOS TargetCarbon TargetMacOSClassic TargetMachO TargetWin32 TargetLinux 


The previous targets all correspond to the build settings that I already covered. The directives TargetCarbon and TargetMacOSClassic are mutually exclusive subsets of TargetMacOS. See the example for System.EnvironmentVariable() later in this chapter for an example of how you can use this to further narrow down which version of the system you are running on. In addition to those targets, you can also target desktop applications that run with a graphical user interface:

TargetHasGui


You can also test to see if your target is a big-endian platform or a little-endian platform:

TargetBigEndian TargetLittleEndian 


If you are a REALbasic old-timer, you should know that these targets have been deprecated:

TargetPPC (Deprecated) Target68K (Deprecated) 


Finally, one last directive is this:

DebugBuild


It allows you to embed code in your application that runs only when you are running it in debug mode, which is when you run it from the IDE instead of running it after you've compiled the application. This allows you to write debugging code that automatically gets stripped out of the finished application so that the real app doesn't suffer any performance hit from the debugging code.




REALbasic Cross-Platform Application Development
REALbasic Cross-Platform Application Development
ISBN: 0672328135
EAN: 2147483647
Year: 2004
Pages: 149

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net