It is probably more useful to update the code to use soft declares.


Charles Yeomans


On Jan 24, 2007, at 2:24 PM, Terry Ford wrote:


On Jan 24, 2007, at 6:15 AM, Emile SCHWARZ wrote:

Hi Tom,

that was a long started project that I am updating. I found Declare everywhere, some encapsulated:

#If TargetMacOS
  #If TargetCarbon

  #ElseIf TargetMachO

(from memory)

can you elaborate - your solution - a bit ?


Tom was correct but a little incomplete. I hope he doesn't mind if I expand a bit on his explanation.

*IMPORTANT*: If anyone spots an error please respond with the corrections as some things in the current Intel Macs are new and I cannot test them on my G5.

What Tom is basically saying is that one can use a constant to simplify referring to the correct Declare library when building on the 4 REALbasic Macintosh formats.

To understand each build type I will refer to the current ones in 2007r1.

1. Mac OS X Universal Binary
2. Mac OS X PowerPC
3. Mac OS X Intel
4. Mac OS X and Mac OS 9

The next thing to consider is the hierarchy of the REALbasic Macintosh #If Target... constants. These are built-in to the IDE.

TargetMacOS Constant- This includes all versions of Macintosh builds. It is, according to the LR, "used to indicate that you are compiling code for any Macintosh OS, "classic" or Mac OS X in either the Mach-O or PEF formats." It is used primarily to differentiate Mac builds from Windows and Linux builds.

Within TargetMacOS, there are two subsets. These are:

a) TargetCarbon - The LR states, "Used to indicate that you are compiling Carbon code." "TargetCarbon is True if you are compiling for Macintosh in either the PEF or MachO formats."

b) TargetMacOSClassic - The LR says, "Used to indicate that you are compiling MacOS 8/9 code on a PowerPC." "TargetMacOSClassic is True only if your code is running on a PowerPC under a 'classic' Mac OS. Macintoshes that use the 68K family of processors are no longer supported. This constant was originally known as TargetPPC."

Within TargetCarbon, there are two subsets. These are

1. TargetMachO - The LR states, "Used to indicate that you are compiling code for the Mac OS X Mach-O runtime architecture. A Mach- O build of a REALbasic application runs only on Mac OS X. The code is in the format for the Mach kernel of OS X."

2. The rest as there is No TargetPEF constant. Well there *sort of is* and you can use it if you create your own constant to define the Library to be used. This is where the LR falls down.

So what Tom is saying is that, in many cases (but not all) you can create a Constant that allows you to use a variable name instead of the actual library name and it will provide the correct name for all Macintosh builds. There are four of them for Mac in the constant declaration frame in 200x.

1. Mac OS - Any of the next three.
2. Mac Carbon PEF - PEF PowerPC builds for OS X and OS 9
3. Mac Carbon Mach-O - Formerly Mac OS X Only
4. Mac Classic - Formerly Mac Classic Only

The nice thing is that you can control the scope of these constants now. You can create them for a class (Window/Control Sub-class/App Sub-class) or a Module. Anything that allows you to "Add Constant" in the code editor.

So How do you do it? Lets use a Module that is Global for an example. (Note: I am a bit weak on the Global nature of constants in Classes. They might be the same as the old module or even more defined.)

I am also going to ignore Win32,Linux and OS 9 Builds.

Select Add (New) Constant:

Give it a name. Some people use Carbon. I prefer MacLib as it is less confusing to me.

Don't give it a default value. Make it GLOBAL in the selector button (Default I think).

Set its type to string.

In the pane below you will see Platform (Any); Language (Default): Value (Empty area).

Click on the menu arrow for Platform in the first line and select Mac Carbon PEF. In the Value of the line type CarbonLib (without quotes as it is a String as you declared in type).

Click on the plus circle in the next line to add a new Platform and select Mac Carbon Mach-O. In the Value area of the line type Carbon (without quotes again). (In 5.5 it's the Add Button)

Now you have covered PEF, Mach-O and UB builds.

Using the Declare example in the LR for DoubleClick, which is woefully out of date, I will modernize it for OS X use.

Your old Mac OS X Declares would have been nested something like:

[#If TargetMacOS] // Optional if other platforms
        #If TargetCarbon
                #If TargetMachO
                        Declare Function GetDblTime Lib "Carbon" () as Integer
                #Else
                        Declare Function GetDblTime Lib "CarbonLib" () as 
Integer
                #Endif
        #Endif
[#EndIf]

By using the MacLib constant you made, you can simplify this to:

[#If TargetMacOS] // Optional if other platforms
        #If TargetCarbon
                Declare Function GetDblTime Lib MacLib () as Integer
        #Endif
[#Endif]

Note that I have used the Constant Name MacLib without quotes as it represents a string.

This should build in all Mac OS X formats if I am correct (excluding OS 9).

This is the best explanation I can offer and if there are any errors or omission, please inform me.

What really is required is something in the docs that puts it all together in a simple easy to find manner.

-Terry

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to