Developer

Yeah, but is it real BASIC?

REALbasic has picked up where Zbasic left off; it's using BASIC, a very simple but effective language. But is REALbasic really BASIC? Larry Loeb takes a look at REALbasic and discusses how you can use it. He also evaluates its overall performance.


I've said it before, and I'll say it again: I've made more money by writing programs in some form of BASIC than by writing programs in any other language, including C. Whether or not that fact sheds any light on how I program, I don’t know. It’s been my experience that, if clients need tasks performed quickly, they'll pay for the speed. I usually get applications up and running fastest when I use a simple language like BASIC. In this article, I’ll describe some of the different versions of BASIC, and I’ll discuss their strong points.

Zbasic
Zbasic was a very good language. It worked on the Mac, and it was designed for those users who found MS-Basic too limiting. The Garriepy brothers put out a fine integrated development package that worked well on the pre-7.5 Mac. I created some neat applications with it. It worked in text, with the properties of objects being passed to them as parameter calls. Its revisions, which followed new system changes, became too complicated for a small operation, however, and Zbasic was discarded.

REALbasic
REALbasic took up the gauntlet; it redefined what a Mac BASIC environment could and couldn’t do. REALbasic uses objects instead of direct parameter calls to specify program elements. Objects can be edited directly—in terms of which properties they possess, though the standard properties are assigned to each object based on what that object is. Windows have different properties—not just buttons. The properties of a program object can be edited individually, and any methods (or code) that need to be attached to an object in order to modify its behavior can be written in BASIC syntax. For example, a PushButton can include the code that you wish to execute when the PushButton is used.

Events
Events occur in a program in response to what a user initiates. When a user causes an event, REALbasic checks to see if the object to which the event was directed contains any code that needs to execute in response to that event. If the object has code for the event, REALbasic will execute that code and wait for the user to cause another event. This process continues until something causes the application to quit (usually when the user chooses Quit from the File menu). By default, REALbasic maintains the usual main event loop, which constantly checks all objects for the occurrence of events. You don't have to install a loop; it already exists for you. Thus, you can concentrate on experimenting with the properties of the program object, and you can decide what you want to happen when an event occurs.

It's important to remember that the user can cause events to occur indirectly. For example, buttons have an event called Action, which occurs when a user clicks the button. The code that handles the response to this event is traditionally called an event handler. But what happens if the button's Action event handler has code that opens another window? When the user clicks the button, the Action event handler opens a window, and REALbasic sends an Open event to the window. The user caused this event indirectly by clicking the button that, in turn, opened the new window. Therefore, don’t assume that events can't occur just because you don't cause them directly.

The application itself
Opening up REALbasic without a program will invoke a screen similar to the one that appears in Figure A. This screen is the development environment, and it lists the individual items.

Figure A
The REALbasic Design Environment appears when you open REALbasic without a program.


Label the window through the properties box. To do so, type the window's name into the properties box. You can add a grow icon to the window by checking the appropriate box. Now, grab an edit field from the tools palette and add it to the window. You can resize the edit field to fit the window. You also can force the window to lock the edit field down to the window corners. (In Figure B, the edit field has been selected, and its properties are visible in the properties box.)

Figure B
When you select the edit field, its properties become visible in the properties box.


Now, you have a window that bounds a text entry field. To add a Select All to the provided Edit menu, select a blank menu item under Edit. The name of the menu item is placed in the text property, and an A is placed in the command property. The command property sets up the keyboard equivalent of selecting the menu item directly. Since the menu operates on the main window, you can invoke the code editor by selecting the main window and pressing the Option tab. The code editor has two parts: the browser to the left and the text entry on the right.

Open the Events category for the window and select Enable Menuitem. This action inserts the header and closer for the type of event. (Note that a sub means subroutine and an event that doesn’t return a value. If the event returns a value, then it’s a function.) In any case, you need to enable a menu item. The general syntax to set a property is as follows:
objectname.propertyname = value

Your object is:
EditSelectAll

The property is:
enabled

And the value is the Boolean:
true

For the executable code for the subroutine, type:
EditSelectAll.Enabled=True

The menu item will be enabled. Now, it can pass events. But you still must specify what the menu's event handler can do. Create a new event handler by selecting that choice under the code editor's Edit menu. A box (like the one in Figure C) will pop up and ask you which item will pass the event that needs to be handled. Select the EditSelectAll item; enter some more code after the header and footer have been generated. This action uses the edit field’s length property to select the entire TextField, as shown in Figure D.

Figure C
Now, you must edit an event handler.


Figure D
The final edit involves using the edit field’s length property to select the entire TextField.


Trying it out
Now, you need to make sure that everything works. In the environment, you can debug by running what you've created. Type some text and invoke the Select All menu choice. The results appear in Figure E.

Figure E
Make sure that everything works correctly.


It should work correctly. The blue will show the select operation result. By the way, the OS (not the program) selects the color.

Conclusion
You’ve put together a small program, and you’ve done it very quickly—utilizing and modifying reusable objects. This object-oriented way of doing things is similar to Visual Basic's approach. REALbasic can import Visual Basic forms and modules and use them. REALbasic's professional edition can create applications that work both in Windows and on the Mac. It’s a true cross-platform environment that’s capable of creating stand-alone applications. You can download a demo copy of REALbasic (along with documents and tutorials) from REALbasic.

Larry Loeb has 20 years of computer journalism experience. He was the consulting editor at the late, lamented BYTE magazine, he launched WebWeek, he ran the online Macintosh section of BIX (the BYTE Information eXchange), and he wrote numerous articles for many major computer magazines. Recently, he wrote a book on Secure Electronic Transactions, the protocol endorsed by MasterCard and Visa that allows merchants, cardholders, and banks to work together over the Internet. For banter, tips, and general screaming, send Larry an e-mail .

The authors and editors have taken care in preparation of the content contained herein but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.

Editor's Picks