Dec 95 Tips
Volume Number: | | 11
|
Issue Number: | | 12
|
Column Tag: | | Tips & Tidbits
|
Tips & Tidbits
By Steve Sisak, Contributing Editor
Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.
TIP OF THE MONTH
Arguments To s In MacsBug
In MacsBug, the s [step] command will take an argument which is either a count or a condition on which to stop. This can be very useful for unwinding a twisty bit of code. For example, if you keep crashing in a particular spot, but you cant tell how you got there or what happened just before, you can break before everything goes wrong and type
s (pc == <badspot>)
Where badspot is where you know things are wrong. Macsbug will step through all of the instructions in between here and there. You can then examine the path taken in the scrollback or, if you turn on the log first, look at it all offline with an editor. With the newest versions of MacsBug, you can even step over mixed mode. Note that its possible for find weirder problems, too:
s (a0 == 0)
will step until a0 equals 0.
s (<addr>^ != <current value>)
will step until the long at <addr> changes.
You can use this trick to find a really wide variety of problems. Should you use this tip, donate my fee to the American Red Cross.
- Tim Dierks
They Said I Couldnt
Return Errors From Constructors
I have read several times that you cant return an error from a constructor. This is not entirely true. See the following code example:
class exampleClass : parentClass
{
exampleClass( int arg1, OSErr& errOut );
// initialization constructor
...etc....
};
exampleClass::exampleClass( int arg1, OSErr& errOut )
: parentClass() // parent class constructor explicitly called
, memberData() // instance variable's explict constructor
{
// errOut = noErr; see note #4 below
errOut = someSystemCall( arg1 );
}
void main ( void )
{
OSErr err;
exampleClass aVar( 12, err );
if ( err != noErr )
{....etc....
}
This example obviously returns error information.
However, errOut will NOT have a known value if the following occurs:
1. parentClasss explicit constructor throws an exception.
2. memberDatas explicit constructor throws an exception.
3. someSystemCall throws an exception. This example used explicit contructor calls, but the same is true for implicit constructor calls to parent classes and member data varables.
4. if the errOut = noErr line is uncommented, then at least errOut can have a known value in the absence of other exceptions.
Of course, since main isnt doing try/catch, then the test of err != noErr is not going to happen when an exception occurs, either.
- C. Keith Ray
Is Your App Windowshade Savvy?
Many apps change the cursor within certain areas of their windows. This may be to provide the crosshairs in a drawing window, or a hand cursor if something can be dragged in an area of your window. Unfortunately, many applications forget to check whether their window is windowshaded or not. If their window is windowshaded but still the front window, they go ahead and change the cursor anyway, leading to the effect of the cursor changing over empty space. Looks ugly. Heres the fix:
if (EmptyRgn( ((WindowPeek)TheWindow)->contRgn ))
//window shade has been used
Dont change the cursor;
else
Go ahead and change the cursor;
In the above example, TheWindow is the windowptr to the window whos areas we are changing the cursor for.
- Richard Unger and Eric Bourque
Shortcut to Open Header Files In CodeWarrior
Here is a feature that Id long hoped for, and recently, by accident, found.
In Metrowerks IDE, typing command tab will open the corresponding .h or .cp file. For example, if youre working in a source file named FileName.cp typing command tab will open FileName.h. This is an extremely useful feature that I hope Symantec will adopt.
- Norman Basha
Drop Into MacsBug at a Predictable Address
When dropping into MacsBug, I often find myself in the wrong applications code. For example, lets say I want to force-quit the finder using es from MacsBug. (command-option-escape will quit and then restart the Finder). To make sure the Finder is the frontmost app, I hold the mouse down in one of the Finders menus and press the interrupt key, and Im dropped in at a known location (a small loop within the menu manager). Not only that, but the current menu manager is emulated on PowerMacs, further ensuring my safety. Then a simple es quits the Finder.
- Damon Cokenias
Lock Your Libraries, Prevent Changes
Heres a tip that may be obvious, but its useful, if somewhat simple.
If you dont want to modify the standard libraries included in a development environment (the source to PowerPlant or TCL for example) you can use the following script to lock all the files. I use this script in MPW, but should work with ToolServer as well:
### First set the current directory to the folder containing the sources
to lock
### note that this script does sub-folders also.
### replace "xxx" with your path, e.g., "HD:MPW:Interfaces:"
directory "Full path to the folder in which the files are:"
### Then set the lock bit to ON for all files which are of
### type 'TEXT' in the current directory and all sub-directories
### Notes:
### remove "-r" to skip sub-directories
### make the "L" lowercase ("l") to un-lock files
### the -f is for full paths, -s to supress directory listings
SetFile -a L `files -r -f -s -t 'TEXT'`
Anyway, just thought Id pass it on. Its particularly useful while using a class browser like Object Master, where you can browse all classes and its easy to end up editing one of the supplied classes in PowerPlant/Think Class Library/MacApp.
- Tyler Morrison
[AppleScript also supports locking and unlocking of files. Simply modify the locked property of x, where x is a file alias or file name with: set the locked of file x to true
EdAsst - jtk]