Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > PHP/MySQL/Scripting

Writing REALbasic Code

  • Print
  • + Share This
Learn how to control your objects' behavior by exploring REALbasic's syntax and Code Editor. Walk through an HTML editor example and by the end of this sample chapter, you will be able to write your own REALbasic code.
This chapter is from the book

As you saw in Chapter 3, "Programming Object Properties," object-oriented programming is all about objects and the properties and behavior of those objects. In that chapter, you learned how to manipulate the properties of objects. In this chapter, you'll learn how to control objects' behavior by writing code in REALbasic's programming language.

Unlike the original BASIC programming language, REALbasic is an object-oriented language. In this sense, it is more like C++ or Java than it is like BASIC. As you'll see in Chapter 5, "Writing Object-Oriented Code," this distinction affects how you structure your programs. But at the level of the individual command, REALbasic code looks a lot like traditional BASIC code. The syntax is similar.

In this chapter, you will learn that syntax. You'll also learn how to get the most out of REALbasic's Code Editor, your primary tool for writing REALbasic code. In the process, you will add code that extends the capabilities of the HTML editor that you built in Chapter 2, "Building an HTML Editor." By the end of this chapter, you will know how to write your own REALbasic code.

Creating Behavior Without Programming

In some cases, you can program the behavior of objects in REALbasic without writing any code. Certain objects, such as PushButton controls, have obvious and natural behaviors associated with them. A handy REALbasic feature called object binding lets you assign the obvious behavior to the appropriate object without doing any coding. In every case, the obvious behavior involves another object and binds the two objects together. Creating a binding between a PushButton control and a MoviePlayer control, for example, can cause the movie to play when the button is clicked. Note, though, that object binding works only with controls and only with certain controls.

To create an object binding between two controls:

  1. Holding down the Shift and Command keys, drag from the source object (the one that will do the controlling) to the destination object (the one that is to be controlled).

  2. In the New Binding dialog that appears, choose the desired behavior, and click OK (Figure 4.1). A line will appear, connecting the two objects and signifying the binding (Figure 4.2).

Figure 4.1Figure 4.1 By creating an object binding between two objects, you can cause one to control the other.

Figure 4.2Figure 4.2 When you create an object binding between two objects, the IDE shows it as a line connecting the objects.

To examine an object binding:

  1. Select the line connecting the objects by clicking it.

    In the Properties window that appears, you see the active object binding that is represented by this line.

Note that an object can have more than one binding. A CheckBox control, for example, might have an object binding that causes a MoviePlayer control to play its movie when the CheckBox is checked and another that causes the movie to stop playing when the CheckBox is unchecked.

To modify an object binding:

  1. Select the line representing the binding.

  2. Press the Delete key.

  3. Create a new binding as described earlier in this section.

To find out what object bindings are available for a given object:

  • Holding down the Shift and Command keys, drag from the source object to the destination object as though you were creating a binding.

    You can read the possible bindings between these objects in the dialog that appears (Figure 4.3).

    Figure 4.3Figure 4.3 A pair of objects can have more than one object binding.

Consult the REALbasic Developer's Guide for the full list of possible bindings for all objects.

Object binding is one way of controlling the behavior of objects. After it has been created, an object binding controls the objects' behavior just as though you had written the appropriate REALbasic code. But no REALbasic code is being written in the background by the object binding. The only way to modify an existing object binding is to follow the preceding procedure.

Object binding is a useful tool, and it's worth your time to build some object bindings to experience how this feature works. But although object bindings can save you time and effort, the only way to build full REALbasic applications is to write REALbasic code. And you do that in the Code Editor.

  • + Share This
  • 🔖 Save To Your Account