Cover image for REALBasic: TDG, 2nd Edition

Book description

REALbasic is a programming language in the best Macintosh tradition: visual, intuitive, and easy to learn. It allows you to create interfaces in minutes and entire, compiled applications without having to learn a complicated language; the strong object orientation makes it very easy even for beginners to develop, maintain, and alter projects. Best of all, an REALbasic 3, a single button click generates your project as a Mac OS 8/9 application, a Mac OS X native ("Carbon") application, or a Windows executable. No other application framework lets you compile for users on so many platforms so quickly and easily. REALbasic: The Definitive Guide not only gives you a firm grasp of the program's essential concepts, but also tells you things you won't learn from the official documentation alone. If you've never programmed before, the book offers both a primer in REALbasic and an intuitive approach to the concepts of programming itself, as you quickly reach the ability to program every aspect of REALbasic. You start out drawing the interface much as you would do in a drawing program: by selecting buttons, menus, dialog boxes, and the like from a tools menu. Then you use the code editor to fill in the code that tells these pieces what to do. The widely hailed first edition of REALbasic: The Definitive Guide has been completely rewritten to encompass reader suggestions and the many improvements of REALbasic 3--like its ability to compile and run under OS X. The book is divided into three sections:

  • Fundamentals: a detailed summary of the language that quickly shows you how to think about programming and accomplish your goals in less time

  • User Interface: how to create a complete application using the rich classes and pre-defined tools that make life so much easier for the REALbasic programmer.

  • Reaching Out: Internet communications, databases, multimedia, game programming and more!

Table of Contents

  1. REALBasic: TDG
    1. Preface
      1. How This Book Came to Be Written
      2. What REALbasic Is Like
      3. Versions, Editions, and Systems
      4. Acknowledgments
      5. How to Contact Us
      6. Conventions
      7. Beyond This Book
    2. I. Fundamentals
      1. 1. The Workspace
        1. The Project Window
          1. The Project
          2. Project Components
          3. External and Imported Components
          4. Folders
        2. Editing Windows
          1. The Tools Window
          2. Manipulating Controls
          3. The Properties Window
        3. Adding Functionality
          1. Code Editors
          2. Editing and Executing Code
          3. Maintaining Code
        4. How the Three Editors Relate
          1. Editing Property Values
          2. Initial Values and Subsequent Values
          3. Names
        5. Testing Without Building
        6. Online Help
        7. Shortcuts
      2. 2. The Basic Language
        1. Lines and Commands
        2. Variables and Constants
          1. Assignment
          2. Datatypes and Declaration of Variables
          3. Constants
        3. Subroutines
          1. Subroutine Declarations
          2. Return
          3. Calling a Subroutine
            1. Calling a procedure
            2. Calling a function
            3. Parameter matching
          4. Flow and Side Effects
          5. Editing Subroutine Declarations
          6. Pass by Reference
        4. Regulating Flow
          1. If and Select
          2. While
          3. Do
          4. For
          5. Exit and GoTo
        5. Arrays
          1. Declaring Arrays
          2. Resizing Arrays
          3. Multidimensional Arrays
          4. Array Parameters
        6. Recursion
        7. Comments
      3. 3. Objects, Classes, and Instances
        1. Messages and Dot Notation
        2. Object Design Philosophy
          1. Encapsulation of Functionality
          2. Maintenance of State
          3. Summary
        3. Classes and Instances
        4. Anatomy of a Class
        5. An Instance Is Born
          1. The Application Class
          2. The Default Window Class
          3. Control Classes
          4. Menu Items
          5. Noncontrol Classes
        6. Referring to Instances
          1. Maintaining a Name
          2. Functions as References
          3. Self
          4. Resolution of Names
          5. Referring to Controls
          6. Me
          7. The Window Global Instance Name
        7. The Truth About Controls
        8. Control Clones and Control Arrays
          1. Control Arrays
          2. Cloning in the IDE
          3. Cloning in Code
        9. Being Careful with Instance References
          1. Initialization Is Not Instantiation
          2. Assignment Is not Cloning
            1. Short names
            2. Linked data structures
            3. Multiple references
          3. Parameters Pass Pointers
          4. Comparison Tests Identity
        10. Destruction of Instances
      4. 4. Class Relationships and Class Features
        1. New Classes and Inheritance
        2. Casting
        3. Overriding
        4. Class Interfaces
        5. Events and New Events
        6. The Class Hierarchy
        7. Global Members
          1. Modules
          2. The Application Subclass
        8. Advanced Class Features
          1. What’s My Window?
          2. Constructors and Destructors
          3. Overloading
          4. Class-Directed Messages
          5. Privacy
          6. Class Properties and Class Methods
        9. Example Classes
          1. Stack Class
          2. Array Class
          3. Hash Class
          4. Map Class
      5. 5. Datatypes
        1. Booleans
          1. Coercion of Booleans
          2. Side Effects
        2. Strings
          1. Concatenation and Conversion
          2. Length, Search, Comparison, and Sort
          3. Substrings and Case
          4. Extending REALbasic’s Abilities
          5. Converting Between Encodings
        3. Numbers
          1. Coercion of Numbers
          2. Bases
          3. Operators
          4. Trigonometry and Exponentiation
          5. Miscellaneous Arithmetic
          6. Internal Representation
        4. Variants
          1. Coercion of Varients
          2. Templates
        5. Collections
        6. Dates
          1. Date Class Properties
          2. Date Calculations
        7. Colors
        8. Memoryblocks
          1. Creating a Memoryblock
          2. Exchanging Data with a Memoryblock
          3. Using Memoryblocks for Speed
        9. Threads
          1. Creating and Using a Thread
          2. Arbitration of Threads
      6. 6. Menus
        1. Menu Overview
          1. How Menus Are Enabled
          2. Menu Item Classes
          3. Cloning Menu Items
        2. Editing Menus
        3. Special Menu Items
        4. The Menu-Enabling Moment
          1. What It Is
          2. What Happens During It
          3. How It Is Triggered
          4. Menu Enabling on Windows
        5. Menu Item Functionality
          1. Menu Events
          2. Menu Event Handlers
          3. Modifying Default Menu Item Functionality
        6. Dynamic Menus
        7. Menu Examples
          1. Creating the Menus
          2. The Application Subclass
          3. The Window
          4. The EditField
          5. The Font Menu
          6. The Window Menu
          7. Cross-Platform Considerations
      7. 7. The Architecture of an Application
        1. Three Pillars of Zen
          1. Events Make Choices
          2. Scope
          3. References Are the Thread
            1. Parameters
            2. Drops
            3. Choosing between a parameter and a drop
        2. The Application Subclass
        3. Order of Events
      8. 8. Debugging and Building
        1. Compile Errors
          1. Punctuation Problems
          2. Dangling Participles
          3. Number of Parameters
          4. Define Your Terms
        2. Exceptions
          1. The Calling Chain
          2. Exception Blocks
          3. RuntimeException and Its Subclasses
          4. Raise
          5. Custom RuntimeExceptions
        3. The Debugger
          1. Breakpoints and Stepping
          2. The Debugging Windows
          3. Additional Debugging Strategies
        4. Building
          1. Minor Options
          2. Build Type
          3. Heap Size and Memory Management
          4. Pragmas
          5. Target Flags and Conditional Compilation
    3. II. User Interface
      1. 9. Windows
        1. Window Types
          1. Modal, Nonmodal, and Floating Windows
          2. The Frame Property
          3. Global Floating Windows
        2. Opening and Closing, Showing and Hiding
          1. Invisible Windows
          2. When a New Window Is Shown
          3. ShowModal
        3. Title, Position, and Size
        4. Events
        5. Drawing in a Window
      2. 10. Abstract Control Classes
        1. Lifetime Events
        2. Appearance
        3. Position and Size
        4. Mouse Movement Events
        5. Redrawing
      3. 11. Canvases
        1. Canvas Events, Properties, and Methods
        2. Picture Class
          1. Properties
          2. Getting a Picture
        3. Graphics Class
          1. Pen-Based Drawing
          2. String Drawing
          3. Pixels and Pixel Blocks
        4. Backdrop Property
          1. Imported Image File
          2. Imported Resource File
          3. Image File at Runtime
          4. File Resource at Runtime
          5. NewPicture
        5. Fun With Graphics Properties
          1. Image Transformations
          2. Changing a Backdrop
          3. Animation
          4. Limitations of Graphics Methods
        6. Canvas Graphics Property
          1. Paint Event
          2. Smooth Animation
          3. Scrolling
        7. Transparency and Icons
          1. Transparent Property
          2. Mask Property
          3. Icons
        8. Speed
          1. Prepared Images
          2. Nonflickering Canvas
          3. Pixel Access
        9. Interaction with Other Objects
          1. Screen Shots
          2. Shifting Other Controls
          3. Covering Other Controls
      4. 12. Buttons and Static Texts
        1. PushButton
        2. BevelButton
        3. Placard
        4. LittleArrows
        5. CheckBox
        6. RadioButton and GroupBox
        7. DisclosureTriangle
        8. StaticText
        9. Custom Buttons
          1. Colored Right-Aligned RadioButtons
          2. Popdown List
      5. 13. EditFields
        1. Types of EditField
        2. EditField Events, Properties, and Methods
          1. Physical Characteristics
          2. Focus
          3. Selection, Text, Font, and Style
          4. Keyboard
        3. The Focus
          1. Summary of Rules About the Focus
          2. Order of Focus-Related Events
          3. Controlling the Focus in Code
          4. Floating Find Window
          5. Validation Field
        4. Manipulating Text and Styles
          1. Tickertape Field
          2. Styled Word Processor
          3. Styled HTML Editor
          4. Word Selection Field
          5. Finding Styles
          6. Scrolling
          7. Combining EditFields
        5. Reacting to User Input
          1. After the Fact
          2. Intercepting Input
          3. Code Field
          4. Live Input Validation
        6. Drawing Styled Text
        7. Miscellaneous Tips
      6. 14. ListBoxes
        1. ListBox Features
        2. ListBox Events, Properties, and Methods
          1. Contents and Format
          2. Selection
          3. Hierarchy
          4. Headings and Sorting
          5. Checkboxes and Editable Cells
          6. Keyboard
          7. Focus
        3. Basic ListBox Techniques
          1. Contents and Formatting
          2. Column Display
          3. Pictures
          4. Selection
        4. Hierarchical ListBoxes
          1. One Folder Row
          2. General Single-Depth Hierarchy
          3. General Multiple-Depth Hierarchy—First Try
          4. General Multiple-Depth Hierarchy
        5. Other ListBox Features
      7. 15. Progress Bars, Sliders, and Scrollbars
        1. ProgressBar
        2. Slider
        3. Scrollbar
          1. Scrolling Canvas
          2. Scrolling Pane
          3. Big ListBox
          4. Scrolling Nonwrapping Field
      8. 16. Shapes and Decorations
        1. Line
        2. Shapes
        3. Separator
        4. ImageWell
        5. ChasingArrows
        6. PopupArrow
      9. 17. Menus in Windows
        1. PopupMenu
          1. Contents and Format
          2. Selection
          3. Usage
            1. Initialization
            2. Changing an item’s text
            3. Independent caption
        2. BevelButton
          1. Contents and Format
          2. Selection
          3. Usage
        3. ContextualMenu
          1. Contents
          2. Selection
          3. Usage
        4. Alternatives
      10. 18. TabPanels
        1. Preparation
        2. Properties and Events
        3. Usage
      11. 19. Keyboard
        1. Keyboard Communication
        2. Keyboard Object
          1. AsyncCommandKey and Its Friends
          2. AsyncKeyDown
          3. CommandKey and Its Friends
        3. UserCancelled
      12. 20. Mouse and Cursor
        1. Mouse Communication
          1. Mouse Movement
          2. Mouseclick
        2. Polling the Mouse
        3. Balloon Help
        4. Cursor
          1. Getting a Cursor
          2. Negotiating the Cursor
          3. Overcoming the Watch
          4. Animated Cursors
    4. III. Reaching Out
      1. 21. Files
        1. Getting a FolderItem
          1. GetFolderItem and GetTrueFolderItem
          2. Volumes
          3. Special Folders
          4. User Dialogs
          5. Relative FolderItems
        2. File Types
        3. File Properties and File Actions
          1. File Properties
          2. File Actions
          3. Recursive Techniques
          4. AppleScript Techniques
          5. Aliases
        4. Arbitrary Data: Binary Streams
          1. Getting a BinaryStream Instance
          2. Reading and Writing Data
          3. Saving and Restoring Preferences
        5. Sequential Data: Text Streams
          1. Reading
          2. Parsing a Mailbox File
          3. Writing
          4. Find-and-Replace
        6. Resources
          1. Getting a ResourceFork
          2. Referring to Resources
          3. Parsing Resources
        7. Predefined Data Formats
          1. Sounds
          2. Pictures
          3. Movies
          4. Styled Text
          5. References to Files
      2. 22. Databases
        1. Database Files and Classes
          1. Database Class
          2. DatabaseRecord Class
          3. DatabaseCursor and DatabaseCursorField Classes
        2. Schemas
        3. Displaying Data
        4. Other Data Sources
      3. 23. Clipboard
        1. Clipboard Class
        2. Usage
          1. ListBox Copy-and-Paste
          2. Show Clipboard
          3. Private Scrap
      4. 24. Drag-and-Drop
        1. Beginning a Drag
          1. The DragItem
          2. Multiline EditField
          3. ListBox
          4. MouseDown Receivers
        2. Receiving a Drop
        3. Finder Drop
        4. Internal Drag-and-Drop
        5. Limitations and Workarounds
      5. 25. Time
        1. Ticks and Microseconds
        2. Timers
          1. Getting a Timer
          2. Timer Behavior
          3. When Timers Run
          4. Timers as Idle Handlers
        3. Yielding Time
      6. 26. Sound
        1. Beep
        2. Sound Object
        3. MIDI Notes
      7. 27. Movies
        1. Movie Class
        2. MoviePlayer
          1. Appearance
          2. Action
          3. Events
        3. Movie Usage
        4. Making Movies
        5. Analyzing Movies
      8. 28. Animation
        1. Configuring the SpriteSurface
        2. Basic Sprite Techniques
          1. Motion
          2. Image Animation
          3. User Interaction
          4. Collisions
        3. Basic Background Techniques
        4. Improving the Classes
        5. Intelligent Sprite Behavior
        6. Responding to Keys
        7. Intelligent Collisions
      9. 29. Printing
        1. Page Setup
        2. Proceeding To Print
        3. Measurement Problems
        4. Printing Text
      10. 30. TCP/IP Communications
        1. Socket Properties, Methods, and Events
          1. Connecting and Disconnecting
          2. Receiving Data
          3. Sending Data
          4. Errors
          5. Yielding
        2. Client
          1. Buffered Read
          2. Dictionary Client
          3. Buffered Write
          4. SMTP Client
        3. Server
          1. Web-Based Time Server
          2. Tiny Web Server
          3. Multiple Connections
      11. 31. Interapplication Communications
        1. Sending Apple Events
          1. Anatomy of an Apple Event
          2. Building an Apple Event
          3. Remote Targets and Send-to-Self
        2. Receiving Apple Events
          1. Apple Event Scriptability
          2. AppleScript Scriptability
          3. The Object Model
        3. Apple Event Classes, Properties, and Methods
          1. Classes
          2. Building and Parsing an Apple Event
          3. Records and Lists
          4. Building an Object Specifier
        4. Apple Event Inadequacies
        5. AppleScripts
        6. Shell
      12. 32. Language Extensions
        1. Direct Toolbox Calls
          1. Know Your Enemy
          2. Declare Your Datatypes
          3. Parsing and Passing Structs
          4. Sharpening Pointers
          5. Grasping Handles
          6. Who Was That Masked Man?
          7. 68K
          8. Windows
        2. XCMDs
        3. Shared Libraries
        4. Plug-ins
    5. A. Growing an Application
      1. Principles of Approach
      2. An Example Project: Tic-Tac-Toe
        1. Won’t You Be My Neighbor?
        2. Three in a What?
        3. What’s My Row?
        4. He Thought About the Game
        5. Can We Talk?
        6. May I Cut In?
        7. Three in a Row
        8. Draw, Partner
        9. Stop the World, I Want to Get Off
        10. Cleanup
      3. Exercises
    6. Index
    7. Colophon