Articles 3D Audio Custom Controls General RB Graphics Hacks Mac OS X Menus Novelty Printing REALbasic 2005 REALbasic 2006 Registration Resources Reviews Serial Speech Sockets XML Video Resource Links News Current News February 2006 January 2006 December 2005 November 2005 October 2005 September 2005 August 2005 July 2005 June 2005 May 2005 April 2005 March 2005 ![]() REALbasic for Dummies by Erick Tejkowski ![]() Learning REALbasic through Applications REALbasic for Macintosh REALbasic Cross-Platform Application Development
Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander |
|
Debugging in Mac OS X with REALbasic by [an error occurred while processing this directive] 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 earlierSendToConsole 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 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. |
||||
|
||||||||||||||||||||||||||||||||
Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement.
[an error occurred while processing this directive]