It’s Alive! It’s 5.5!

What’s New in the Latest Version of REALbasic

Matt Neuburg

Matt Neuburg is the author of REALbasic: The Definitive Guide, and a member of the editorial board of REALbasic Developer. This article was originally published in REALbasic Developer Issue 2.4 (March/April 2004).

The white-coated folks in REAL’s laboratory have been tinkering for a year since the last major version (5.0), and the results are impressive. Here’s a survey of the main changes to expect in REALbasic 5.5. (The standard disclaimers apply: I’m describing the latest beta available at the time of writing, but things could change while we go to print; and, no animals were harmed during the production of this article.)

The Big Picture

REAL has started to implement building Linux applications (RedHat and SuSE, initially); I’ve no direct experience of this, but I’m told that the effort is still largely inicipient. There’s no Linux IDE, either; you develop on Mac or Windows, just as in the old days you could develop for Windows only on Mac. But cross-platform development is easier than before, because now there’s remote debugging.

Here’s how remote debugging works. Let’s say you’ve two machines (which we’ll think of as local and remote). They can be running different operating systems: for example, Mac OS X locally and Windows remotely. On the remote machine, you run a server app called the stub. On the local machine, you run the REALbasic IDE, and you tell it where the stub is (on a local network, it will discover the stub automatically). Now you develop locally as usual, but when you want to run in the IDE, instead of Debug > Run, you choose Debug > Run Remotely. Presto, REALbasic builds for the appropriate platform and, by talking to the stub, copies the built app to the remote machine and launches it! Human interaction with the running app takes place on the remote machine, but the debugger, if we drop into it, appears on the local machine. Thus the edit-run-debug cycle is extremely convenient when cross-compiling; it also avoids window refresh issues that can arise when editing and debugging on the same machine.

REALbasic can now also build console apps, meaning faceless apps to be called from the command line. The App object is an instance of ConsoleApplication, and on startup its Run method is called with an array of command-line arguments. The Run method can interact with the Terminal via Input and Print calls, and when it exits, the app quits. Optionally, a console app can be a service app, where “service” means (as on Windows) a server process intended to run even without a user logged in; here, the App is a ServiceApplication instance. Also, REALbasic Mac OS X apps can now be Mach-O, enabling declares to Mach-O shared libraries and frameworks.

There are two more major reorganizational moves. The REALdatabase engine has been rewritten, and is now part of the standard license. And the Office Automation plug-ins are abandoned; this feature is now built into the IDE.

IDE and Language

Improvements to the IDE, especially when debugging, are too numerous to list in full; but the following are particularly noteworthy. Project Templates now actually do something: they appear in the Templates dialog when you make a new project. Properties can have comments. When editing code, command-option-A selects the current block, and can be repeated to expand the selection blockwise outwards. A new contextual menu item lets you Find the word clicked on; this is great for jumping to a method’s declaration. Variable values are editable in the debugger.

There are also many improvements to the REALbasic language. Compound boolean #if expressions, and #elseif, are now legal in conditional compilation. There’s a new command (break) to drop into the debugger from code. At last there’s a line continuation character, so long lines can be wrapped; the character is underline (_), and you can enter one and start a new line conveniently by typing option-return.

msgbox "This could be " + _
    "a very long line!"

The case statement has more flexible syntax. There’s a new way of passing optional parameters: the ParamArray keyword causes a parameter to “mop up” all subsequent arguments into an array, as in Perl. And declaration of a variable can be combined with initialization:

dim i as integer = 4
dim c as new MyClass("howdy")

Arrays have been largely rationalized. An array can now be assigned to a variable, passed ByRef, or returned from a function; and an array parameter can be multidimensional. Arrays are now “co-variant”; this means that if a ClassA instance is acceptable where a ClassB is expected (because, for example, ClassA is a subclass of ClassB), then an array of ClassA is acceptable where an array of ClassB is expected. (This was true in earlier versions of REALbasic, but in a non-rigorous fashion that could cause crashes.) The array method populates an array from a list of values, the shuffle method randomizes an array, and the indexOf function finds a value within an array.

dim arr() as integer = array(1,2,3,4)
arr.shuffle
msgbox str(arr.indexOf(1))

Constants can be created in a class or window, and can be referenced with dot-notation. Constructors and destructors can be named constructor and destructor. Module members can now be private, public, or global; “public” means the member can be accessed from anywhere but only by dot-notation with the module name, which helps to carve up the global namespace. Class members can be private, protected, or public; “protected” means what used to be called “private”, and “private” access is now limited to code within the class itself.

At long last there is proper exception handling. Earlier, to catch an exception in a range of code smaller than a handler you had to factor that code into a handler of its own. Now there’s a try...catch...finally block, as in Java.

MemoryBlocks and Strings

A memoryblock can be treated more like a string: memoryblocks can be concatenated, compared, and subjected to midB, and the two types can be assigned to one another. Strings, meanwhile, at last have split and join functions, not as good as Perl’s but better than nothing.

The new StyledText class allows object-oriented platform-independent manipulation of text styling. This has been my personal number one desideratum for years, so I’ll quickly demonstrate. Here, we populate an EditField with text where every other word is bold:

  dim st as new styledtext
  dim sr as stylerun
  dim i as integer
  dim s as string = "hello out there, folks in REALbasic land!"
  dim words() as string = s.split(" ")
  for i = 0 to ubound(words)
    sr = new stylerun(words(i) + " ")
    sr.font = "Palatino"
    sr.size = 14
    sr.bold = (i mod 2 = 1)
    st.appendStyleRun sr
  next
  editfield1.styledtext = st

Here, we change all an EditField’s bold text to italic:

  dim st as styledtext = editfield1.styledtext
  dim i,u as integer = st.StyleRunCount - 1
  dim r as range
  for i = 0 to u
    if st.stylerun(i).bold then
      r = st.styleRunRange(i)
      st.bold(r.startPos, r.length) = false
      st.italic(r.startPos, r.length) = true
    end
  next

One can serialize an EditField’s contents, both text and style information, to disk in a cross-platform manner; demonstration code is provided by REAL’s indefatigable Aaron Ballman.

To top it all off, the new XMLNode and related classes permit parsing and creation of XML, along with XSLT processing and XPath queries; this is based on the Sablotron engine (see References).

Windows and Controls

The msgbox call is superseded by the MessageDialog class, which constructs flexible standardized alerts. There are new BevelButton types on Mac OS X, icon transparency now works, and icons can at last be any kind of picture. EditField masks and formats can assist with entry validation and display of values. A ListBox now has a variant CellTag property, which should make for more flexible supplying of data. Limits on the values for ProgressBars and ScrollBars are much larger. There is a new ComboBox control; at this point, it seems primitive but serviceable (and better, in any case, than the hack in my book).

Other Miscellaneous Changes

At long last there is translation from a keycode to a string. Game input devices (such as joysticks) and pen tablets are supported. Any QuickTime compatible sound format can be played as a sound (not just as a movie, as formerly), and there is now a built-in method for text-to-speech. There are classes for accessing the Mac OS X AddressBook. Mac OS X threading is smoother, and no longer blocks during certain user interactions. A new call, doEvents, yields time to the system, so the trick of launching a Timer is no longer needed.

There are many improvements to TCP/IP communication classes: for instance, basic authentication and proxy support has been added, and there’s better handling of headers. Particularly nice is the addition of some easy classes for auto-discovery and basic TCP and UDP communication; these are not meant for implementing major protocols, but are simply to make it easy for you to write applications that talk to one another over a network. As a final touch, SOAP support has been added.

The new addressOf operator takes the address of a global method, making it possible to write a Declare to a function that calls back into your code. A typical example is when you want to implement a Carbon Event — that is, you register with the System to have a certain method called when a certain event occurs. The function that wants the address of your method is NewEventHandlerUPP. Having declared it:

Declare Function NewEventHandlerUPP Lib "CarbonLib" (address as Ptr) as Ptr

you can then call it like this:

myPointer = NewEventHandlerUPP(AddressOf MyCoolMethod)

This should give you a general sense of what’s new for 5.5. There are some areas I haven’t even mentioned (the Project Manager, for instance), and of course I apologize if I’ve left out anyone’s favorite new feature; do consult REAL’s official release notes for full details.


Mach-O (developer documention):
.../Performance/Conceptual/Performance/Carbon/Carbon_and__able_Format.html
Sablotron:
http://www.gingerall.com/charlie/ga/xml/p_sab.xml
Carbon events (developer documentation):
.../Carbon/Conceptual/Carbon_Event_Manager/Tasks/chapter_18_section_4.html