Borland Delphi 1.0

Just a few months ago, Bob Cringely's InfoWorld gossip column carried a piece to the effect that Microsoft had been using Borland Delphi to put together a new visual tour guide. This raised more than a few eyebrows, particularly because the tour guide was intended to form part of Microsoft's latest incarnation of the Visual C++ (VC++) development system. As a rule, development-system vendors are not noted for building their software with other vendors' products.

So what exactly is Delphi? And what makes it so attractive that--allegedly--even Microsoft's programmers want to use it? In essence, it's a child of the union between Borland's stunningly fast object-oriented Pascal compiler and a Visual Basic (VB)-style front end.

There are similarities between VB and Delphi. Components of both have properties that enable you to control their appearance and behavior. For example, double-clicking on a component at design time immediately puts you in a code-editor window (see Screen 1), where you can enter the code for a new event handler (a small piece of code that responds to an event such as a key press or a mouse click). Both follow a Rapid Application Development (RAD) paradigm when building a user interface. With this approach, you lay out one or more controls--components in Delphi-speak--on a form and then link them together by writing event handlers. But there, the similarities end.

The Design Environment
In VB, the Toolbox grows larger as you add more controls to the system. In Delphi, the Component Palette (the Delphi equivalent of the VB Toolbox) is split into tabbed pages that enable you to neatly divide a large number of components into different functional groups. For example, the upcoming 32-bit version of Delphi has a palette page called Win95, which contains all the new Windows 95 controls. Thus, the Component Palette remains relatively compact even if you install a number of controls.

The Object Inspector is the Delphi equivalent of VB's Properties window. If you use the same "paged" approach as the Component Palette does, you can instantly flip between a component's properties and its event handlers. The Object Inspector also supports nested properties: For example, the Font property is further subdivided into subproperties, such as Color, Height, Style, and so forth. The Style subproperty is nested into fsBold, fsItalic, and more. While VB gives you a "flat" property layout, a single component in Delphi can potentially have a property hierarchy.

Laying out components on a form is easier in Delphi, too. Size and Align dialogs can be used to precisely align components or to force a group of components to be one size.

For user-interface design, Delphi includes container components. A container is a component you can put other components--and other containers--in. This may sound like an odd thing to do, but imagine you want to put a panel with a list box and several push buttons in a dialog box. When you drag the "parent" panel around, the "child" components move with it. Effectively, containers let you build forms within forms. Delphi has several different types of containers, including Panels, GroupBoxes, NoteBooks, and Tabbed NoteBooks.

Another interesting feature of the Delphi design environment is the synergy between the Form Designer and its associated code window. Every time you place a component onto a form, you see the equivalent object-oriented component's definition appear in the code window. Similarly, changes made in the code window are immediately reflected in the Form Designer. Borland calls this approach Two-Way Tools.

In addition, there's the compilation speed: I've yet to see a C++ compiler that I can describe as "speedy." In contrast, Borland's Pascal compilers have always moved quickly, partly because they forgo the industry-standard object file format. Instead, they use a proprietary system that enables the compiler to store a snapshot of its symbol-table information inside each object file. You can compile a moderate-size Delphi application in just a few seconds. Borland claims a compilation speed of around 350,000 lines per minute for a 90-MHz Pentium. The benefits in programmer productivity alone are significant.

Delphi for Database
Despite being at heart a general-purpose development tool, Delphi is geared toward database connectivity. In the entry-level version, its emphasis is on local database support. It includes a copy of the Borland Database Engine (BDE), which can be used to access Paradox, dBASE, and InterBase files or to route via Open Database Connectivity (ODBC). Applications built with the entry-level system can be scaled up to the full client/server version to provide Borland SQL Links drivers to connect to Sybase, Oracle, Microsoft SQL Server, Informix, and others.

The client/server version of Delphi also includes Visual Query Builder to create SQL queries interactively, and a client/server version of Borland's ReportSmith, a report writer. Early developers of BDE applications had trouble figuring out how to set BDE up on a target machine as part of a software installation. However, commercial installation programs that fully support BDE (e.g., Eschalon Setup Pro) are beginning to appear.

To create a database from scratch, you'd typically use the Database Desktop application to specify the database type, the record layouts, and any aliases. This enables your application to refer to the database with logical names instead of physical locations and filenames.

Delphi contains two pages on the Component Palette which are related to database work: the Data Controls page, which contains a rich set of data-aware controls such as DataSource, and the Data Access page, which contains a set of controls used to provide database access such as Table.

With one or more data-aware controls on a form, you'd typically point the DataSource property of each control at a single DataSource component. The DataSet property of the component points at a Tablecomponent.TheTablecomponent refers to a specific database--DatabaseNameproperty--and a specific table within that database--TableName property.

This may sound complicated, but it's a lot easier to use than it is to describe. Why are all the data-aware controls vectored through an intermediate DataSource component? By changing its DataSet property, all the dependent controls automatically refer to a different database or table. This indirection scheme saves you from having to change many individual properties in each control. (See Screen 2 for an illustration of how this works.)

Distilled Delphi Development
Delphi programming stands on two foundations: Object Pascal and the Visual Component Library (VCL):

  • Pascal is the object-oriented programming language which Borland has developed and refined during the last few years. This language made its appearance in Turbo Pascal 5.5 and has been through a number of subtle--and not so subtle--changes. Object Pascal formed the basis of the Object Windows Library (OWL), Borland's application framework for Windows, and was the heart of TurboVision, the equivalent framework for DOS.
  • A mature technology, Object Pascal is admittedly not as powerful as C++. For example, it doesn't have multiple inheritance, operator overloading, or support for templates. However, in my opinion multiple inheritance is rarely essential in real-life programs and the other two features are essentially semantic conveniences. With Delphi, Borland has added some new features to Object Pascal. For example, structured exception handling is a technique that allows your program to recover from error conditions in a controlled manner without having to code dozens of error-handling statements.

The most important change in the language, however, has to do with support for the Visual Component Library (VCL). In Object Pascal, component, property, and event-handler capabilities are built right into the language. These capabilities have made a few additions to the compiler necessary, but it's still backward-compatible.

  • is a whole new application framework that replaces OWL and provides a solid basis for component-based programming. Components are central to Object Pascal. Unlike VB, which can't create VBX controls--those from a Dynamic Link Library (DLL) containing user-developed VB controls--Delphi can create new components. Among other things, VCL effectively provides an object-oriented "wrapper" around the Windows application programming interface (API). This wrapper is far more convenient to use than the bare API and can result in much smaller source code.

Another difference between VB and Delphi: VBX files are separate from the program's .EXE file while a Delphi component is linked into the program and becomes part of its executable file. A VB program that uses VBX files must be able to find them at runtime. Although Delphi's process increases the size of its executable, the program is inherently more self-contained. Delphi also supports calling VBX files as part of your VCL framework. You can even use legacy VBX files, if you wish.

The code in listing 1a shows a VB program that draws randomly colored lines within a window. The corresponding Delphi code is shown in listing 1b. Because Delphi shares many component property names and event handlers with VB, a number of automated conversion tools claim to be able to convert a VB program into its Delphi equivalent.

Hitting the Metal
Unlike VB, the Pascal language on which Delphi is based is a true compiled language. This has a number of important consequences.

First, a Delphi application is much faster than its VB equivalent--from five to 20 times as fast, depending on the type of program. If you're trying to decide between VB and Delphi, this fact alone gives Delphi the edge for compute-intensive applications that require a lot of number-crunching. In VB, each instruction has to be interpreted by the interpreter DLL; in Delphi, a program is executed directly by your CPU, just as it would if it were written in C or C++.

Second, because no interpreter is involved in Delphi, you don't need a separate interpreter package. In VB 4.0, the 16-bit interpreter DLL (VB40016.DLL) requires 935KB, while its 32-bit equivalent (VB40032.DLL) takes 721KB. These numbers can be important when you need to minimize the number of distribution disks that your software needs. They can be crucial for shareware authors having their programs distributed on disks sent with magazines.

A less obvious benefit is Delphi's ability to "hit the metal" when required. Because Delphi is based on a real compiler, it's relatively easy to implement low-level features such as interrogating processor registers or communicating with device drivers. You can use a special feature called an in-line assembler to embed machine code directly into your application. This feature gives Delphi a tremendous amount of flexibility. Within one code module, you can make high-level SQL calls and pass registers to an undocumented interrupt. Delphi can do this without requiring any third-party DLLs; VB can't.

There are some disadvantages to not having an interpreter: A Delphi application is generally much larger than its VB equivalent. The minimum size for a Delphi program is about 200KB, whereas a VB program can often be only a few KB in size. However, you also need to factor in the size of the VB runtime DLL.

Because Delphi is a true compiler, you can use it to build new DLLs, something VB can't do. You can write screen savers, Control Panel applets, and more with Delphi. A big question for Windows NT developers is whether you can use Delphi to write server applications and embedded services. Creating them with the upcoming 32-bit version should be possible, but how easy it is, in practice, will depend on how much work Borland does. The situation is analogous to writing VBX controls with the 16-bit version of Delphi: It can be done, but it's an uphill struggle. Borland may make things easier by providing a framework into which you can put your own service code. Delphi's Application Expert (see Screen 3) can walk you through the initial creation of your program. Its Gallery feature (see Screen 4) provides canned functionality you can use in creating a new object or form.

Delphi, NT, and the Future
At press time, only a 16-bit version of Delphi was available. Although you can run 16-bit Delphi applications under both Windows NT and Windows 95, a 32-bit system is what's really needed to fully exploit the power of NT. A 32-bit version of Delphi is currently in beta testing. It will provide direct access to NT's 32-bit API. In other words, you'll be able to create Delphi applications that fully exploit Windows NT's multithreading capabilities.

The 32-bit version of Delphi will provide VCL-level support for the common controls built into Windows 95, such as progress bars, image lists, and property sheets. (These common controls will be available under NT once the new shell is available.) In other words, it should be easy to create a single, great-looking 32-bit application to run under both Windows NT and Windows 95.

The 32-bit version of Delphi will also include full support for the new 32-bit Object Linking and Embedding (OLE)-enabled custom controls (OCX) and a means of controlling OLE Automation servers. Perhaps best of all, recompiling existing 16-bit applications for 32 bits will be easy, as long as you've used the VCL library, where possible.

As in C and C++ programming, it's perfectly possible--with care--to write source code that compiles for both 16 bits and 32 bits. Delphi makes this process even simpler by removing the hurdles, such as different memory models, near and far pointers, and so on.

One significant disadvantage to Delphi is its lack of support for non-Intel architectures. Turbo Pascal (Delphi's ancestor) was heavily tied to Intel processors, and a good deal of the Delphi compiler was written in machine code for optimum performance. With the move to 32 bits, Borland has rewritten extensive portions of the compiler. I'm told that it's now just as fast, but without the machine-code dependencies.

In addition, the 32-bit version of Delphi uses the same back-end code generator as Borland's C/C++ development system. For more information on the 32-bit version of Delphi, see the sidebar "What's in Store with 32-bit Delphi?")

The bottom line: Borland hasn't made any commitment to port Delphi to the PowerPC, MIPS, or Alpha platform, but given the runaway success of Delphi 1.0, the company is in a much better position to do so than it was 18 months ago. If Borland does decide to port Delphi to non-Intel platforms--or even to OS/2--it ought to be able to do so now from both a financial and a technical standpoint. Time will tell.

A Timely Reminder
Delphi is a powerful and productive system for general-purpose and client/server development. Its emphasis on component and form reusability, the RAD approach, fast compilation (relative to C++), and fast runtime execution (relative to VB) make for a nearly irresistible package.

The only significant advantage that VB holds over Delphi is the advisability of going with a single-vendor product, particularly since Borland has no immediate plans to port Delphi to non-Intel platforms. Ultimately, the future of Delphi--and Borland's object-oriented Pascal dialect--depends on Borland's willingness to move its product line to other hardware.

More than anything else, however, Delphi represents a timely reminder to us all of just how intuitive and straightforward object-oriented programming was meant to be. That can't be bad.

See the sidebar "VB vs. Delphi: What's the Difference?"

Delphi 1.0

System Requirements: 386 or higher, Windows NT 3.11
or later, 8MB of RAM, 50MB of disk
space, CD-ROM drive (or 31/2" floppy)
Borland International
Phone: 408-431-1000
Price: $199.95 (Delphi 1.0 Desktop Version introductory offer), $1999.95 (Delphi 1.0 Client/Server Version)
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.