What's New In REALbasic 2005?
Volume Number: 21 (2005)
Issue Number: 7
Column Tag: Programming
What's New In REALbasic 2005?
A look at what's new in REAL Software's recently released update to REALbasic.
by Will Leshner
REALbasic 2005 Is Out
REAL Software recently released an all new version of REALbasic called REALbasic 2005, and you might be
wondering what all the fuss is about. REALbasic 2005 was first announced at REAL World (REAL Software's annual
REALbasic developers conference) in 2004, and it was finally released in June of this year. It sports an
entirely redesigned user interface, new controls, additions to the REALbasic language itself, and a new "Rapid
Release" shipping schedule that promises a new version of REALbasic every 90 days.
To really appreciate some of the things I'll be talking about, you'll want to run REALbasic for yourself.
If you don't have a license, you can download the REALbasic demo from the REAL Software website.
Made With REALbasic
With the release of REALbasic 2005, REAL Software hasn't just redesigned the REALbasic IDE, they have also
rewritten it in REALbasic. The IDE itself is now the best example of a made with REALbasic application. This
alone is a great step forward for REALbasic, because it means that the REAL Software engineers are now
fulltime REALbasic developer, and they will now benefit from the improved efficiency that working in REALbasic
provides. That means features should be quicker to implement and should appear in releases more quickly. It
also means that the REAL Software engineers will experience the same bugs and design flaws in REALbasic as
their customers, making it much more likely that fixes will appear sooner, rather than later.
Figure 1. All-in-one project window.
The most obvious change to the REALbasic IDE is the all-in-one project window (as shown in Figure 1). This
change may take some getting used to, but it has several advantages over the old multi-window approach. First,
the new IDE is a joy to use on Windows. If you haven't had a chance to use older versions of REALbasic on
Windows, you may not be aware of some of the problems, but there were several and they affected productivity
substantially. One problem with the old IDE was that it used floating windows for both the controls palette
and the properties editor. While a floating window approach worked well on the Mac, it didn't work well on
Windows, where the floating windows would fight with the main IDE window for the focus. The main window itself
was also a problem on Windows. It was an MDI-style window that severely limited a developer's ability to
switch from one code or layout window to another.
Another feature of the new IDE's one-window approach is that it simplifies having more than one project
open at the same time. A serious limitation with the old IDE was its inability to open more than one project
at a time. Developers managed to work around that limitation through tricks, such as having more than one copy
of the REALbasic application running at the same time. With REALbasic 2005, such tricks become unnecessary,
because opening multiple projects is fully supported by the IDE. Furthermore, having multiple projects open at
the same time is easy to manage for developers because each project is fully contained within its own window.
IDE As Web Browser
The REALbasic 2005 IDE models itself on a tabbed web browser. In a web browser, you visit web pages. In the
REALbasic 2005 IDE, you visit editors. Each editor you visit in a project can be thought of as a location,
just as the different web pages you visit in a web browser can be thought of as locations.. In the REALbasic
2005 IDE, you can jump directly to a location using the Location field at the top of every project window. For
example, if you wanted to jump directly to the Open event of the App object, you would type App.Open in the
Location field and hit return to have the IDE take you directly to the code editor for that event. Also like a
web browser, as you visit code editor locations, the IDE will remember where you've been. You can move back
and forward through the locations you have visited by clicking the backward and forward buttons in the IDE's
main toolbar (see Figure 2).
Figure 2. Browser-like project navigation controls.
If you find that there is a particular location you visit a lot, you can set a bookmark to that location.
Choosing a bookmark from the Bookmarks menu opens the location for that bookmark. Bookmarks are global across
all projects, which means that you can select a bookmark for a location in a project that isn't open, and the
IDE will automatically open the project and take you directly to the location in that project. There is also a
favorites bar, located below the main toolbar, into which you can place bookmarks that you use a lot. The
bookmarks in the bookmarks bar are local to a project and will not show up in other projects.
Most of your time using the REALbasic IDE will likely be spent in the main content area, located below the
main toolbar and the favorites bar. The main content area is tabbed, with each location you visit contained
within its own tab (see Figure 3). One of the advantages to the new tabbed interface is the ability to
quickly switch from one location in a project to another simply by clicking tabs. If you need to see two
locations at the same time, it is possible to open another project window for the current project by choosing
New Window from the File menu.
Figure 3. Project tabs.
Most tab locations have the same basic structure. At the top is a bar of buttons for common actions
specific to that particular location. The Project tab, for example, has buttons for adding classes, modules,
and menu bars, to a project. A code editor tab has buttons for adding methods, properties, events, and other
code elements (Figure 4 shows the menu editor toolbar). Below the command bar is the main content area for the
tab. The look of the main content area will depend on the type of tab. The Project tab contains a list of all
the classes, windows, modules, and other elements contained within that project. A code editor tab contains a
list of all of the methods, properties, events, and other code elements for the item being edited, together
with a code editor pane for editing those items. A window layout tab contains a pasteboard for editing a
window, a list of controls to add to the window, and a properties editor for editing the properties of the
window or the items contained on that window.
Figure 4. Menu editor command bar.
Most of the editors in REALbasic 2005 have been redesigned, and perhaps the biggest change is the way the
new window editor works. The old IDE's window editor looked, and in many ways acted, like a real window. There
were, however, several problems with editing a window that itself acted like a real window. First, every class
instantiated directly on the window had to be contained within the window itself. Some classes, like Timers
and TCPSockets, are not really controls and do not appear in the UI of the running application. The presence
of these non-controls during the design phase tended to clutter the window, and generally got in the way when
trying to position and style those elements that really were controls. Another problem with the old window
editor was that you could never design a window that was larger than your monitor. If you had a small monitor
and a large window, you were forced to play games with the position of the window in order to design it.
Lastly, there was a problem with the old window editor on Windows that had to do with maximizing all the
windows in the project. Because a window editor was just another window as far as Windows is concerned, it
would get maximized along with all the other windows, which was clearly not the desired behavior.
The new window editor in REALbasic 2005 fixes many of the problems of the old window editor. The window
being edited is now contained within a pasteboard, and you can drop objects anywhere on the pasteboard, not
just on the window. So, for example, if a window is to have a Timer on it, the Timer can be placed on the
pasteboard, next to the window, keeping it outside the confines of the window itself. Also, the pasteboard has
scrollbars, which means that you can edit a window of any size, regardless of the size of your monitor.
Finally, the new window editor solves the problem on Windows where the window being edited is treated like a
real window. The window is actually just a picture in the IDE, so Windows won't maximize it in unfortunate
In addition to the window editor, the code editor has also gotten a face lift in the new IDE. The most
obvious change is the addition of guidelines to show you which code blocks belong together. The guidelines are
especially useful when the code in a method has several nested blocks and the code itself is a bit too long to
all fit on one screen. The lines make it immediately obvious which End If goes with which If. The lines also
server a functional purpose. Clicking a line selects all the text in that block.
Most Improved: Searching
Perhaps one of the best features of the new REALbasic IDE is its vastly improved searching options. There
is still a traditional find dialog, from which you can find and replace text throughout a project. New, in the
REALbasic 2005 IDE, however, is the ability to perform regular expression and whole word searches. Search
really shines, however, when you do a Find All. All found items are displayed in a separate search tab.
Double-clicking an item in a search tab brings you directly to the location for that item. But you don't have
to leave the search tab in order to replace some or all of the found items with new text. At the bottom of
each search tab is a field into which you can type replacement text. To perform a replace, all you have to do
is type replacement text, select the items in the list of found items you want to replace, and click the
You do not need to visit the Find dialog in order to search for items in a project. There is a search field
in the main toolbar of the project window into which you can type text to do an instant search. A popup in the
search field lets you set the scope of the search to the entire project, the current item, or the current
method. If you are running Mac OS X Tiger, then you get one more option that is really cool: computer. A
computer search uses Apple's new Spotlight technology to search all the REALbasic projects on your computer
for a given search term. In order to use this option, you will need to download and install REAL Software's
Spotlight plugin for REALbasic. Once you do, you will be able to perform lightning-fast searches of all of the
projects on your Mac. As with any search, the results will appear in their own search tab. Double-clicking one
will automatically open the project for that item, if the project is not currently open.
Figure 5. A customize dialog.
The new REALbasic IDE is much more customizable that the previous versions. For example, every toolbar you
see can be customized. If you don't like a particular command button, you can remove it. If you don't like the
order of the buttons, you can rearrange them. Some command buttons aren't even visible by default. Add Binding
and List Bindings, for example, are two commands you might like to have easy access to that also happen to
have buttons associated with them. By default, window editor toolbars don't include those to buttons. To add
them, just bring up the customize dialog for the window editor toolbar (shown in Figure 5) and add either or
both of them.
The only downside to REALbasic 2005's toolbar customization process is that you need to be looking at a
toolbar in order to edit it. It may not occur to you that some toolbars can be edited. The debugger toolbar,
for example, lacks a Run button, but you can add a Run button using the debugger's toolbar editor. You must be
running in the debugger in order to access that editor, however.
I've only scratched the surface of all of the new features to be found in the REALbasic 2005 IDE. In
addition to those things I've already talked about, there is also a totally new Language Reference, a new
debugger, file type sets, and code refactoring tools. I'll leave these new features for you to discover on
New Language Additions
The IDE isn't the only thing to get new additions in REALbasic. The REALbasic language has had a few
additions to it as well, and all of them are welcome. Here are a few of the more exciting additions.
It was once the case that REALbasic required all variable declarations to appear at the top of a method,
before any other code. That restriction was relaxed in REALbasic 5 so that a Dim statement could appear
anywhere at the top level of a method. Now, in REALbasic 2005, variables can be declared inside blocks as
well. And, as you would expect, the scope of such a variable is the block itself. Which means that the
following silly code, while illegal in REALbasic 5, is perfectly legal in REALbasic 2005:
dim x as Integer = 2
if x = 3 then
dim y as Integer = 4
x = y
Another addition to the REALbasic language having to do with declaring variables is the ability to declare
the loop variable of a for statement directly in the statement itself, as this code demonstrates:
for i as Integer = 0 to 10
j = j + i
New Static Keyword
One thing sorely lacking in REALbasic is class properties and class methods. As in C++, static properties
and methods would be shared by all the instances of a class. They enable class instances to coordinate their
behavior, and they also make the Singleton design pattern a possibility (you can fake singletons now in
REALbasic, but you can't get the compiler to enforce them for you). REALbasic 2005 doesn't introduce static
property and class methods, but it does introduce Static as a keyword of the language and that gets us half
way to static properties and methods.
Static is used like Dim to declare variables in a method. The difference is that variables declared Static
persist across calls of the method, and their value is shared by all callers of that method (in other words,
Static works in REALbasic the way it works in C). Static variables can be declared in module method or class
method. Static variables in class method are static to the method and not to any particular instance of that
method. Which means that every instance of the method sees the same static variable.
Static variables declared in methods of a class can be used by instances of that class to communicate with
each other. One common example is keeping running total of all of the instances of a class that are currently
in existence. Things are a little tricky because the static variable is private to the method in which it is
declared, so we can't really define a cluster of support methods around one static variable. Instead, what we
can do is create one method to which we pass commands for acting on the static variable. In the case of an
instance count, we would need commands for incrementing the count, decrementing the count, and returning the
count. Our final method might look something like the following:
private function InstanceCount(aCmd as String) as Integer
static count as Integer
dim result as Integer
select case aCmd
count = count + 1
count = count - 1
result = count
To use InstanceCount, we would simply need to call InstanceCount("INCREMEMNT") in the constructor for our
class, and InstanceCount("DECREMENT") in its destructor. We could also provide a public method for getting the
instance count that would just return InstanceCount("GET").
Another very useful new feature in REALbasic is the ability to create soft declares. Declares are a way to
call a functions in shared libraries. They are commonly used to get at platform-specific functions of the
operating system that are otherwise unavailable to pure REALbasic code.
Up until REALbasic 2005, a function specified in a declare was hard-coded in the executable and resolved
when the application launched. If the OS couldn't figure out what shared library and function a particular
declare referred to, then the application would fail to launch. In REALbasic 2005, it is now possible to make
a declare "soft", which means that the declared function is not resolved until runtime. A new
IsFunctionAvailable method has also been added to the System object. IsFunctionAvailable makes it possible to
determine, at runtime, whether a function specified in a declare is or is not available, and take action
An example may help to clarify the issue. I'll use a silly declare to make the point, but I hope you can
see how the idea can be extended to other, more interesting declares. Imagine we are writing a custom control
and we need to know the system's double-click time in order to handle double-clicks properly. There is a
Carbon function called GetDblTime that will return that number, so we dutifully construct the following
Declare Function GetDblTime Lib "Carbon" () as Integer
At which point we decide to test things out, so we run the project. There are two possible outcomes,
depending on whether we are building a Mach-O application or a PEF application. If we are building a Mach-O
application, our application will launch and the above declare will perform correctly. If, however, we are
building a PEF application, we will get an error dialog at application launch telling us that the Carbon
shared library could not be found. That is because the PEF loader doesn't know about a shared library called
"Carbon", as we have identified it in the declare above. The PEF loader does know about a shared library
called "CarbonLib", and if we had constructed the above declare using "CarbonLib" instead of "Carbon", then
our PEF application would launch correctly.
A soft declare solves this problem. It defers the resolution of the "Carbon" shared library to runtime,
instead of load time. Furthermore, it is the REALbasic framework that does the resolving and not the PEF
loader, so it can be a bit smarter about handling a declare to "Carbon" in a PEF application. Turning the
above declare into a soft declare is as easy as adding the Soft keyword to the front:
Soft Declare Function GetDblTime Lib "Carbon" () as Integer
Amazing as it may seem, simply adding the Soft keyword resolves the entire PEF versus Mach-O problem. The
declare will now function correctly in both kinds of applications.
Soft declares solve a whole host of problems. On Linux, for example, there is a particularly nasty problem
having to do with declaring to functions in LibC. On many distributions of Linux, LibC is really just a linker
script for gcc that tracks down the real LibC shared library. Before REALbasic 2005, it was necessary to
construct declares using a path to LibC itself, which resulted in code that was decidedly non-portable.
Furthermore, you'd have to know where LibC lived on the particular distribution of Linux on which you were
planning to run your application. Soft declares solves this problem as well. In REALbasic 2005 all you have to
do is create a soft declare to "LibC" and then REALbasic resolves the real location for you at runtime.
New Controls And Classes
In addition to a brand new IDE and additions the REALbasic language, REALbasic 2005 also comes with several
new classes and controls that developers can add to their bag of tricks. I'll cover a couple of them here.
Figure 6. HTMLViewer on Mac OS.
Figure 7. HTMLViewer on Windows.
REALbasic developers have long wished for a built-in HTML control and in REALbasic 2005 that wish has been
granted. The HTMLViewer uses the default HTML rendering technology on each platform. On Mac OS, that
technology is WebKit, on Windows it is Internet Explorer, and on Linux it is Mozilla.
I was lucky enough to be attending WWDC when Apple first announced WebKit. I really enjoyed the
web-browser-in-three-steps demonstration that the Apple engineers performed during several of the sessions I
attended. Now, that same demonstration is possible with REALbasic, and the result is a web browser that runs
on Mac OS, Windows, and Linux. It doesn't take much to whip up a web browser in REALbasic 2005. In fact, it
only takes one line of code. To begin, start with a blank desktop project. Drop an HTMLViewer control, an
EditField, and a PushButton onto Window1. Then, in the Action event for PushButton1, add this code:
That's all there is to it. Run the project, enter a URL into the edit field, push the button, and start
browsing. Figures 6 and 7 show the resulting web browser running on both Mac OS and Windows.
Before REALbasic 2005, if you had a set of controls that worked together as a group, and you wanted that
same set of controls to appear either in different places on the same window, or in different windows, then
you had no choice but to recreate the exact same set of controls in each place that you needed them to appear.
That problem is solved in REALbasic 2005 with the introduction of the ContainerControl. A ContainerControl
acts a little bit like a window in that you design one in a window editor. But instead of appearing as a
separate window, a ContainerControl is attached to another window, either at design time, or in code at
runtime. One ContainerControl can be attached to any number of windows. In fact, you can even embed one
ContainerControl inside another ContainerControl. Furthermore, ContainerControls are first-class citizens in
REALbasic. You can attach properties, events, and methods to them in order to encapsulate their behavior in
the ContainerControl itself.
There are a number of ways that ContainerControls can be used to simplify the creation of a complex user
interface. For example, creating resizable panes becomes almost trivial with ContainerControls. By locking the
bounds of each control contained within the ContainerControl appropriately, it is a simple matter of resizing
the ContainerControl itself to get the effect of a resizable pane.
Figure 8. ContainerControl with two buttons.
Let's work through an example to see how ContainerControls can be used to easily solve a tricky problem.
Anybody who has had to create cross-platform dialogs is well aware that the order of the OK and Cancel buttons
as they appear in a dialog is different on Windows and the Mac. In order to have the buttons appear in the
right order on each platform, it is usually necessary to write custom code in each dialog's Open event to take
care of switching the buttons to the right order, depending on the platform. With ContainerControls, however,
this becomes a simple task that can be solved once and forgotten. Start by creating a new ContainerControl in
an empty project. Onto the ContainerControl drop two PushButtons, changing the Caption property of one
PushButton to OK, and the other to Cancel. It is necessary to arrange the buttons in the proper order for one
of the platforms on which the application will run. In Figure 8 I have arranged the butons in Mac OS order.
The next step is to place code in the ContainerControl's Open event to switch the button order when the
application is running on Windows (the buttons are already in the right order for the Mac). This requires a
#if conditional compilation directive, as follows:
dim bp as Integer
bp = CancelButton.Left
CancelButton.Left = OkButton.Left
OkButton.Left = bp
The final step is to place the ContainerControl inside of another window, where it can be instantiated when
the window is created. Figure 9 shows what this might look like. If you now create Windows and Mac OS versions
of the app and run them on their respective platforms, you should see the OK and Cancel buttons appear in
their correct positions for each platform. Furthermore, the ContainerControl we created to solve this problem
is reusable. We can drag it to any window or dialog box to get the exact same effect.
Figure 9. ContainerControl on a window.
In addition to new controls, REALbasic 2005 comes with several new classes, as well as additions to
existing classes. One addition that is particularly welcome are extensions to the BinaryStream. BinaryStreams
are used to read and write binary data in a file. That hasn't changed in REALbasic 2005. What has changed is
that BinaryStreams can now be used with MemoryBlocks and Strings as well. The trick to getting a BinaryStream
to use a MemoryBlock or a String is to pass a an existing String or MemoryBlock to a BinaryStream when
constructing one. For example, here is how you would create a BinaryStream that operated on a MemoryBlock,
instead of a file:
dim mb as MemoryBlock
dim bs as BinaryStream
mb = new MemoryBlock(0)
bs = new BinaryStream(mb)
A BinaryStream that has been created with a MemoryBlock can be used just like any other BinaryStream. The
difference is that instead of reading and writing data from a file, the BinaryStream will read and write data
from a MemoryBlock instead. In the past, when I needed a memory-based stream class, I wrote it myself. But the
new REALbasic implementation is much better than my home-grown one. Because BinaryStream is the stream class
in all cases (MemoryBlock, String, or file), code can be written that reads and writes BinaryStreams that
never has to know that the underlying data lives in a MemoryBlock instead of a file. That means more general
code that can be reused in interesting ways.
REAL SQL Database
One new feature in REALbasic 2005 that is of particular interest to me is the addition of a new single-user
database engine based on SQLite. In case you haven't heard of it, SQLite is a powerful and speedy SQL database
engine with a growing user base. In fact, Apple has included SQLite in Mac OS 10.4 and provided access to it
through its new CoreData technology. By choosing SQLite, REAL Software has guaranteed that REALbasic
developers will have access to a state-of-the-art, high-performance database engine.
Access to the SQLite database engine is through the REALSQLDatabase class. The REALDatabase class still
exists for backward compatibility, but it has been deprecated, and REAL Software suggests we move to the new
database engine as soon as possible. The API for the new REALSQLDatabase class is exactly the same as that of
the REALDatabase, so moving code over to the new database should be as easy as finding every occurrence of
REALDatabase and replacing it with REALSQLDatabase. It will be necessary to convert any existing databases,
however. The REAL SQL Database only understands SQLite databases (and only SQLite 3 databases, if that means
anything to you). REAL Software provides a conversion utility on their website to convert databases made with
the REAL Database into REAL SQL Databases.
The strength of SQLite is its speed, robustness, and ability to handle a wide range of SQL syntax. If you
are looking for a way to have both a local single-user database and a remote multi-user database in the same
application, then the REAL SQL Database is definitely worth a look. By taking advantage of REALbasic's
Database classes and the database engines that support them, it is possible to talk to several different
databases at once in the same application. For example, you could create an application that talked to a MySQL
database if it is available, but fell back to a local REAL SQL Database when access to the MySQL database
isn't available. For the most part, you could even feed exactly the same SQL to both database engines, making
the transition between the two seamless.
Before REALbasic 2005 was released, it was possible to run the REALbasic IDE on three platforms: Mac OS
Classic, Mac OS X, and Windows. REALbasic 2005 loses one platform, but gains another. The lost platform is Mac
OS Classic. While it is still possible to build Classic applications, the REALbasic IDE itself is not
supported on that platform. In exchange for Classic, we get Linux. Although it has yet to go final, REAL
Software is currently conducting on open beta of the Linux IDE. REAL Software has also announced that the
Standard version of the Linux IDE will be free. I have to admit that I'm not as familiar with Linux
development as I am with Mac and Windows development, but now that there will be a development IDE that I am
already familiar with on Linux, I'm looking forward to adding Linux to the platforms I can support with my
New Release Schedule
As if REALbasic 2005 and all of its exciting new features aren't enough, REAL Software has also announced a
new release schedule to go along with it. In the past, new major versions of REALbasic arrived anywhere from
six to eighteen months apart from each other. This created a problem for both REAL Software and REALbasic
developers. For REAL Software, the problem was that while their engineers were furiously coding the next major
release, they were also maintaining the current release. As with all software, REAL Software periodically
released maintenance releases of REALbasic in order to provide bug fixes to developers waiting for those
fixes. Maintenance releases would contain bug fixes, and occasionally minor features, but never the big new
features that were being prepared for the major release. Sometimes a particular bug fix was too risky to ship
in a maintenance release, so it, and the developers waiting for it, had to wait for the major release.
REAL Software's new release schedule is based on a rapid release model in which a new version of REALbasic
will ship at least every 90 days. New releases will included both bug fixes and new features. With this new
rapid release model, there will no longer be a need to maintain one release of REALbasic while working on the
next release. Upcoming releases are always both the maintenance release for the current version, as well as
the next major release with new features.
With the new rapid release model comes a new way to buy REALbasic. Instead of paying to upgrade REALbasic
at every major release, developers will pay once for all the updates in a given period of time. New licenses
include six months of updates. Upgraded and renewed licenses include twelve months of updates.
As you can see, there is plenty that is new in REALbasic 2005. The big change, of course, is the new
REALbasic IDE, but almost every aspect of REALbasic has something new to explore. If you haven't yet given
REALbasic a try, you should. REALbasic has always been a good tool for developers to have in their toolbox.
With REALbasic 2005, that tool got even better.
Will Leshner is a full-time software engineer who has also been developing software with REALbasic
for over five years. He writes the From Scratch column in REALbasic Developer, and he also has a weblog
devoted to REALbasic, which can be found at http://rbgazette.com.