Chapter 5
Programming with Delphi

The following sections provide an overview of software development with Delphi and describe some features that are not covered in earlier chapters of this Quick Start.

Development tools and features

The integrated development environment (IDE) includes the Form Designer, Object Inspector, Component palette, Project Manager, Code Explorer, Code editor, Data Module Designer, software localization tools, debugger, and many other tools. The particular features and components available to you will depend on which version of Delphi you've purchased.

All versions of Delphi support general-purpose 32-bit Windows programming, multithreading, COM and Automation controllers, and multiprocess debugging. Some versions add support for server applications such as COM servers and Web applications, database development with report and chart generation for a variety of DBMS back ends, support for SQL database servers (such as Oracle 8 and InterBase), Microsoft Transaction Server (MTS), multi-tiered database applications, CORBA, and decision-support systems. For up-to-date product information, refer to www.borland.com or contact your Inprise distributor.

Using the VCL

Delphi comes with components that are part of a class hierarchy called the Visual Component Library (VCL). The VCL includes objects that are visible at runtime--such as edit controls, buttons, and other user-interface elements--as well as nonvisual controls like datasets and timers. The diagram below shows some of the principal classes that make up the VCL.

Objects descended from TComponent have properties and methods that allow them to be installed on the Component palette and added to Delphi forms. Because VCL components are hooked into the IDE, you can use tools like the Form Designer to develop applications quickly.

Components are highly encapsulated. For example, buttons are preprogrammed to respond to mouse clicks by firing OnClick events. If you use a VCL button control, you don't have to write code to handle Windows messages when the button is clicked; you are responsible only for the application logic that executes in response to the event.

Most versions of Delphi come with complete source code for the VCL. In addition to supplementing the online documentation, the VCL source code provides invaluable examples of Object Pascal programming techniques.

For more information...

See "Visual Component Library Reference" and "Creating Custom Components" in the online Help.

Exception handling

Delphi's error-handling is based on exceptions, which are special objects generated in response to unanticipated input or faulty program execution. Exceptions can be raised at both design time and runtime, and the VCL contains many exception classes that are associated with specific error conditions. In your applications, you'll want to write exception handlers to deal gracefully with runtime errors. Exceptions can also be a valuable debugging tool, since the class of an exception often provides a clue about what caused it to be raised.

For more information...

See the entries for "Exception" and its specialized descendant classes in the online VCL reference. Look up "exception handling" in the Help index.

Database connectivity and utilities

Delphi and the VCL offer a variety of connectivity tools to simplify the development of database applications. The Borland Database Engine (BDE) is a collection of drivers that support many popular database formats, including dBASE, Paradox, FoxPro, Access, and any ODBC data source. SQL Links drivers, available with some versions of Delphi, support servers such as Oracle, Sybase, Informix, DB2, SQL Server, and InterBase.

Delphi includes components that you can use to access data through InterBase Express (IBX). IBX applications provide access to advanced InterBase features and offer the highest performance component interface for InterBase 5.5 and later.

IBX is based on the custom data access Delphi component architecture, and is integrated with the Data Module Designer. IBX is compatible with Delphi's library of data-aware components, and does not require the Borland Database Engine (BDE).

You can create database tables at design time in the Form Designer. First, create field definitions using the Object Inspector, then right-click on the table component and choose Create Table.

Some versions of Delphi include components to connect to databases using ActiveX Data Objects (ADO). ADO is Microsoft's high-level interface to any data source, including relational and non-relational databases, email and file systems, text and graphics, and custom business objects.

For more information...

See "Developing Database Applications" in the Developer's Guide or online Help.

In addition, Delphi provides the following tools for database developers.

BDE Administrator

Use the BDE Administrator (BDEAdmin.exe) to configure BDE drivers and set up the aliases used by data-aware VCL controls to connect to databases.

For more information...

Start the BDE Administrator from the Delphi program group under the Windows Start menu. Then choose Help|Contents.

SQL Explorer (Database Explorer)

The SQL Explorer (DBExplor.exe) lets you browse and edit databases. You can use it to create database aliases, view schema information, execute SQL queries, and maintain data dictionaries and attribute sets.

For more information...

From the Delphi main menu, choose Database|Explore to open the Explorer; then press F1. Or search for "Database Explorer" in the main Help index.

Database Desktop

The Database Desktop (DBD32.exe) lets you create, view, and edit Paradox and dBase database tables in a variety of formats.

For more information...

Start the Database Desktop from the Delphi program group under the Windows Start menu. Then press F1.

Data Dictionary

The Data Dictionary provides a customizable storage area, independent of your applications, where you can create extended field attribute sets that describe the content and appearance of data. The Data Dictionary can reside on a remote server for additional sharing of information.

For more information...

Search for "Data Dictionary" in the Help index.

Kinds of development project

You can use Delphi to write Windows GUI applications, console applications, service applications, dynamic-link libraries (DLLs), packages (a special type of DLL used by Delphi), and other programs.

Applications and servers

Delphi has features that make it easy to write distributed applications, including client/server, multi-tiered, and Web-based systems. In addition to support for standards like COM and a suite of Internet components, some versions of Delphi provide extensive tools for CORBA development.

For more information...

See "Building applications, components, and libraries" and "Developing distributed applications" in the Developer's Guide or online Help.

DLLs

Dynamic-link libraries (DLLs) are compiled modules containing routines that can be called by applications and by other DLLs. Since a DLL contains sharable code or resources, it is typically used by more than one application.

For more information...

Search for "DLLs" in the Help index.

Custom components and packages

A package is a special dynamic-link library used by Delphi applications, the IDE, or both. While packages can be used in a variety of ways, their most common purpose is the encapsulation Delphi components. In fact, all components installed in the IDE must be compiled as packages.

The components that come with Delphi are preinstalled in the IDE and offer a range of functionality that should be sufficient for most of your development needs. You could program with Delphi for years without installing a new component, but you may sometimes want to solve special problems or encapsulate particular kinds of behavior that require custom components.

Custom components supplement the VCL while promoting code reuse and consistency across applications. Many Delphi components are available through third-party developers, and Delphi provides a New Component wizard that makes it easy to create and install components on your own.

For more information...

See "Creating Custom Components" in the Developer's Guide or online Help. Search for "packages" in the Help index.

Frames

A frame (TFrame), like a form, is a container for other components. In some ways, a frame is more like a customized component than a form. Frames can be saved on the Component palette for easy reuse, and they can be nested within forms, other frames, or other container objects.

After a frame is created and saved, it continues to function as a unit and to inherit changes from the components (including other frames) it contains. When a frame is embedded in another frame or form, it continues to inherit changes made to the frame from which it derives.

For more information...

Search for "frames" and "TFrame" in the Help index.

COM and ActiveX

Delphi supports Microsoft's COM (Component Object Model) standard and provides wizards for easy creation of ActiveX controls. Sample ActiveX controls are installed on the ActiveX page of the Component palette. Numerous COM server components are provided on the Servers tab of the Component palette. You can use these components as if they were VCL components. For example, you can place one of the Microsoft Word components onto a form to bring up an instance of Microsoft Word within an application interface.

For more information...

Search for "COM" and "ActiveX" in the Help index.

Type libraries

Type libraries are files that include information about data types, interfaces, member functions, and object classes exposed by an ActiveX control or server. By including a type library with your COM application or ActiveX library, you make information about these entities available to other applications and programming tools. Delphi provides a Type Library editor for creating and maintaining type libraries.

For more information...

Search for "type libraries" in the Help index.

Deploying applications

When you deploy an application, be sure to supply all the required files--including executables, DLLs, packages, and BDE drivers--to your users. To make this process easier, Delphi includes a special version of InstallShield Express, a popular tool for developing installation utilities.

For more information...

Search for "deploying applications" in the Help index.

Internationalizing applications

Delphi offers many features for internationalizing and localizing applications. Support for input method editors (IMEs) and extended character sets is provided throughout the VCL, and tools like the Resource DLL wizard make it easy to prepare a project for localization. To get the maximum benefit from these features, you need to start thinking about internationalization requirements as early as possible in the development process.

The Integrated Translation Environment (ITE), available in some versions of Delphi, is a suite of tools for software localization and simultaneous development for different locales. It is integrated with the IDE to let you manage multiple localized versions of an application as part of a single project.

The ITE includes three tools:

For more information...

Search for "international applications" and "ITE" in the Help index.