|
2-07-02
Debugging in Mac OS X with REALbasic by
Erick Tejkowski
This week we'll take a look at a quick and easy hack to help you
debug Mac OS X projects that you create with REALbasic. Not a lot of glitz this time,
but it is an essential step in your quest for REALbasic "Excellence". (Good tie-in, eh?)
Merlin lovers will have to wait another week for the finished project. (I'm still working on it).
Build the Interface
Interface? We don't need no stinkin' interface! Ok, maybe we need a small one. Launch REALbasic, open Window1
and add a PushButton and an EditField control to the window. You're done!
Add the Code
Choose File-New Module. A new module appears in your Project window. A module is global in nature, which is just a fancy way
to say that all parts of your REALbasic project can use the calls within it. Once we finish this module, you can drag it
from your project and use it in other projects too.
Open the new module and add a method to it (Edit-New Method). Name the Method something you'll remember. This debugging
method is going to send data to the Console application, so name it SendToConsole and add msg as string in the
parameters field of the Method definition. Press OK.
To this new method add the following code:
dim i as integer
#if TargetCarbon then
Declare Sub DebugStr Lib "CarbonLib" (msg as Pstring) as Integer
i = DebugStr(msg)
#endif
This code gives you access to the Mac API call: "DebugStr". Any text that you give to DebugStr will show up in the Console application.
What? You haven't played with the Console yet? Now's the time! It's located here: /Applications/Utilities/Console.app.
The Console application is just a GUI front end for the "old-timey" console, where Unix geeks and programmers like to send
text for viewing. For RB programmers, it's like adding your own window and editfield without doing a thing. As you test your program,
you can follow along with its progression, by littering your code with statements like:
// place this in the PushButton's Action event from earlier
SendToConsole EditField1.text
//put this in an Open event somewhere
SendToConsole("Open event occurred")
//etc...
SendToConsole("Sprite now moving")
SendToConsole("Sprite has stopped")
SendToConsole("Crash doesn't happen here")
SendToConsole("Crash happens here")
As you program executes, these various text messages will appear in the Console application. It's low-tech, but it
gives you another way to debug your applications. If you want to be really slick and do it like "the pros" do it, add
a new Boolean constant to the module by selecting Edit-New Constant.
Then, change the code from earlier to read like this:
dim i as integer
if debugging then
#if TargetCarbon then
Declare Sub DebugStr Lib "CarbonLib" (msg as Pstring) as Integer
i = DebugStr(msg)
#endif
end if
This way you can sprinkle debugging code all over the place and turn it off by redefining the constant as FALSE.
This is fun in OS X, but what about Classic? The DebugStr call works with the Classic Mac OS too, but instead of
sending your text to the console (which doesn't exist in OS 9), the string gets sent to the debugger (i.e. Macsbug).
Since Macsbug is another topic altogether we'll forego the discussion this time. If I hear of enough interest,
I'll gladly talk about it in a future tutorial. It's not terribly scary to use, but it is quite a bit different than
the console.
Conclusion
No glitz this week, but you will have lots of glory if it helps you
track down a nasty bug. You can download this week's project and example application, in case you don't want to create the
project by hand. Have fun and see you next week when we'll hopefully wrap up our Merlin project.
2-05-02
REALbasic News
by
Erick Tejkowski
TIP: CD Playback in OS X
There are a few plugins around that allow you to playback CD audio from your REALbasic projects, but none that work in OS X.
The good news is that none are required. The MoviePlayer control in REALbasic is perfectly capable of playing
CD audio tracks in Mac OS X (only). Of course, you don't get any of the useful track information that a plugin might afford you, but this
at least gives some RB users an option if they need this functionality. Mac OS X treats the CD audio tracks as AIF files, so play them
in REALbasic just as you would a normal audio file. Cool!
TIP: Shuttle Control
For years, professional audio geeks have had a handy knob on their equipment, called a "shuttle". This knob lets them
scan through audio or video at high speed so they can look and listen for specific segments in the media where they might want to
work. It works much like the fast forward and rewind buttons on your cassette player, but it also allows you to see and hear the
data that is zipping by you. REALbasic users may be surprised to know that they have access to just such a control in their own apps!
To use it, simply load your favorite movie into a MoviePlayer control. Then, while pressing the Control key on your keyboard, click
on the rewind/ffwd buttons of the MoviePlayer's controller. Voila! Instant shuttle control. Neat!
TIP: Temporary Code Space
How many times have you needed to do a search and replace, but only from a subsection right in the middle of your code? You can't simply start the replace
from the top of the code, because the code that comes after the subsection will also be replaced. A simple solution that you may have overlooked:
copy and paste the code you want to alter (or for that matter just "cut" it). Then, create a new method (Cmd-Opt-M) and name "Dummy". Paste your code in this dummy
function, tweak it as desired, and put it back in your original method or event. Dummy methods are a good place to work on shorter code segments or even as a
place to stick reminder messages or documentation of the code. And, unlike external text editors, they have the ability to parse REALbasic code. Handy!
ACGIs on Mac OS X
James Sentman has released a nifty application called acgi dispatcher. This little gem
lets you use AppleEvents with the Apache web server. Not only is this application Made With REALbasic, but its also capable of working with your
REALbasic cgi's. Fantastic!
REALbasic Folklore
Did you know.... At one of REAL Software's first appearances at a MacWorld, their machine for processing credit card numbers unexpectedly stopped working.
A few minutes later, REAL Software had whipped up an application (with REALbasic, of course) that read in the numbers from their card scanner via a Serial control.
REALbasic saved the day for REALbasic. Wacky, but true!
|