Where Developers Matter
Integrated Development Environments for Windows, Java, and Web Developers
| | Log On

Delphi 2005 Reviewer's Guide

By: Cary Jensen

Abstract: The complete Microsoft Windows development solution

Table of Contents

Overview

Delphi: Advancing the Art of Software Development

The Integrated Development Environment

One IDE, Multiple Personalities

One IDE, Multiple Languages

The Structure Pane

The VCL and VCL for .NET Floating Designer

The Tool Palette

Enhanced Tool Palette Behavior

New VCL for .NET Components

The Object Inspector

The Upgrade Project Wizard

Delphi 2005 Wizards

Find in Files Enhancements

Updated Support for International Characters

Message List Enhancements

IDE Error Reporting

Import/Export Project from/to Visual Studio .NET

The Next Generation Code Editor

Refactoring

Symbol Renaming

Variable and Field Declarations

Resource Refactoring

Extract Method Refactoring

Import Namespace (C#) and Find Unit (Delphi)

SyncEdit

Error Insight

Help Insight

The History Manager

The Content Pane

The Info Pane

The Diff Pane

Code Navigation Enhancement

Toggling Code to/from Comments

Persistent Bookmarks

J2EE and CORBA to .NET Integration with Janeva

User Selectable File Encoding

The VCL for .NET

Virtual Library Interfaces

Support for Partially Trusted Callers

The Delphi Compilers

Updates for Both Win32 and .NET Delphi Compilers

The For…In Loop

Support for Unicode and UTF8 Formats

The Delphi for .NET Compiler

Delphi Code and Namespaces

Support for Weak Packaging in VCL for .NET Applications

Forward Declared Record Types

The Delphi Win32 Compiler

Function Inlining

Support for Nested Types

Nested Type Constants in Class Declarations

Support for Pentium 4 SSE3 and SSE2 Instruction Op Codes and Data Types

XML Document Generation

The Delphi Debuggers

Multiple Debugger Support

Exception Dialog Enhancements

The Disassembled View

Breakpoints

The Log Call Stack Breakpoint Option

Breakpoint Dialog Box Updates

Updated Attach to/Detach from Process

Evaluator Frame Support for Win32 Local Variables

Database Development

RAD for ADO.NET

Providing and Resolving with DataSync and DataHub

Data Remoting with RemoteServer and RemoteConnection

Borland Data Provider for ADO.NET

The BDP Data Explorer

Managing Tables

Data Migration

Testing Stored Procedures

Creating Reports in Delphi 2005

Added VCL for .NET Data Access Components

ADO.NET Connection String Editor

Web and Internet Development

Deployment Manager

HTML Editing in the Web Forms Designer

Template Editing

Updated Code Completion and Syntax Highlighting

Updated Tag Editing

Additional ASP.NET Project Manager Support

New and Enhanced DB Web Controls

New DB Web Controls

Updated DB Web Controls

IntraWeb Support

Integrated Application Lifecycle Management

Delphi 2005 and StarTeam

Unit Testing

Enterprise Core Objects

Rapid MDA

ECO Space and Persistence Mapping

ECO and OCL

What's New in ECO II

A Highly Scalable Enterprise Object Cache

Extended Object Capabilities

ECO II Support for Web Forms and Web Services

ECO II Support for Existing Databases

Integrated and Included Partner Tools

Borland Caliber RM

Borland InterBase 7.5 Developer Edition

Borland Janeva

Borland Optimizeit™ Profiler for the Microsoft .NET Framework

Borland StarTeam 6.0 Standard Edition

Component One Studio Enterprise for Borland Delphi 2005

Crystal Reports Borland Edition

glyFX Borland Special Edition

IBM DB2 Universal Developers Edition

InstallShield Express for Borland Delphi

Internet Direct (Indy)

IntraWeb

Microsoft SQL Server 2000 Desktop Engine (MSDE 2000)

Microsoft SQL Server 2000 Developer Edition

Rave Reports Borland Edition

Wise Owl Demeanor for .NET Borland Edition

Other Resources

Summary

About Borland Software Corporation

About the Author

Delphi 2005 Reviewer's Guide

The Complete Windows Development Solution

A Borland White Paper

Produced for Borland by Cary Jensen, Jensen Data Systems, Inc.

October 2004

Contents

  Overview

Welcome to the Delphi 2005 Reviewer's Guide. This document will familiarize you with Delphi 2005, the newest version of Borland's flagship development environment, culminating more than twenty years of technological innovation.

The Delphi 2005 Reviewer's Guide is organized into two parts. In this first part, the Overview, you will find a general introduction to Borland's Delphi 2005.

The second part of this guide takes you on a tour of Delphi 2005. This part, which is organized by the major areas of software development and support in Delphi 2005, provides you with an overview of each area, followed by a description of the many updates, enhancements, and additions introduced in this product. If you are already a Borland enthusiast, you may want to quickly scan the overview section, concentrating instead on the updates that make this the most important upgrade to Delphi since it debuted in 1995.

  Delphi: Advancing the Art of Software Development

Delphi's legacy began in 1983, when Turbo Pascal set a new standard for software engineering. The evolution of Turbo Pascal reads like a history lesson in the advancement of software development, including the introduction of such groundbreaking innovations as an integrated development environment (IDE), integrated debugging, syntax-highlighting, a powerful object-oriented programming (OOP) model, and OWL, the Object Windows Library.

With the release of Delphi 1.0 in February of 1995, Borland proved that component-based development could be applied in an object-oriented environment, permitting developers to rapidly build applications while maximizing code reuse. In more ways than one, Delphi blazed a trail that would eventually be followed the framework class library (FCL) of the Microsoft .NET Framework.

Borland Delphi 2005 represents another impressive advance in software development by Borland, making Delphi 2005 the ultimate and complete development solution for Windows. Delphi 2005 converges Delphi, C#, Microsoft .NET Framework and Win32 support for graphical user interface (GUI), Web, database, and model driven application development, and wrapped with the essential application lifecycle management (ALM) tools into a unified, highly-productive rapid application development (RAD) environment. With Delphi 2005, you have everything you need to increase Windows developer productivity, personal developer productivity, and team productivity.

Windows developer productivity. Delphi 2005's IDE makes Windows development tasks faster, easier, and better by supporting the Win32 standard of yesterday and today with the Windows-based Microsoft .NET Framework development standard of today and tomorrow. With world-class compilers and debuggers, a rich legacy of standards-based tools, and a seamless migration path between current and emerging platforms, there is no better Windows development tool on the market today.

Personal developer productivity. Delphi 2005 takes the power of Delphi to a new level, with speed and productivity enhancements throughout. With a code editor that simplifies every aspect of your programming experience, the largest collection of reusable components, powerful code-generating wizards, and much more, Delphi 2005 is the most prolific development environment available.

Team productivity. Delphi 2005 allows teams to take full control of the application lifecycle. In addition to Delphi 2005's state-of-the-art tools for software development, certain editions of Delphi 2005 also include StarTeam for team source code control, Borland Enterprise Core Objects II (ECO™ II) for model-powered development in the .NET framework, integrated Unit Testing Framework, and Borland Optimizeit Profiler for the Microsoft .NET Framework for performance-testing. In short, Delphi 2005 provides you with a complete, integrated solution for all your development and project management needs.

Borland Products = Technical Excellence

Throughout the years, Borland products have been recognized for excellence and innovation.
Here are a few of the honors received recently by the products that represent the heritage of
Delphi 2005:

● Borland Delphi 8 for the Microsoft .NET Framework won Best of Show in the developer tool category at TechEd Europe, 02-July-04

●  Borland C# Builder won the Visual Studio Magazine Reader Choice Award for best developer tool 24-May-04

●  Borland Delphi 7 Studio won the Web Services Journal Readers' Choice Award for in the Best GUI for Web Services Product category, 25-February-04

Hide image
aw_del8_bos-teched_europe

Hide image
aw_cshp_vsm_best

Hide image
aw_del_wsj-readers-choice

The remaining sections of this guide are organized into related topics associated with software development. Each section begins with a general overview, and then continues with a description of the new and enhanced features introduced in Delphi 2005.

Disclaimer

This reviewer's guide is based on a pre-release version Delphi 2005. Features in the shipping product may vary slightly from the descriptions found here.

   The Integrated Development Environment

Delphi 2005's IDE (integrated development environment) represents the state-of-the-art in software development tools. Growing out of Borland's Galileo IDE technology first release with Borland C# Builder and Delphi 8 for .NET, Delphi 2005's IDE continues Borland's rich heritage of enabling you to develop applications faster and better.

Hide image
Click to see full-sized image

This section focuses on the features found in the various panels, designers, dialog boxes, and views of the IDE. Features that are specific to the code editor are detailed separately in a later section of this guide.

  One IDE, Multiple Personalities

Whether you are coding in Delphi or C#, writing Win32 applications or .NET managed code, building ASP.NET Web pages or traditional client applications, Delphi 2005's IDE provides you with a consistent and powerful set of development tools designed to increase your productivity.

With Delphi 2005, the IDE keeps track of what kind of application you are working with, providing you with the designers, views, and features consistent with the task at hand. For example, if you are building an ASP.NET Web application, the HTML designer allows you to design your Web pages visually, permitting you to drag-and-drop the components that you want to see on your Web page and configure them with little or no code. The following figure shows Delphi 2005 with an open ASP.NET Web application and its visual HTML designer.

Hide image
Click to see full-sized image

If you create a new Win32 client application, or open an existing one, the VCL (visual component library) designer kicks in, again providing you with unmatched support for designing your user interfaces.

Hide image
Click to see full-sized image

You can even create project groups that include two or more different kinds of projects. When you do this, the type of application that is currently active in the project group determines which designers are available, and which options you see in the supporting views. For instance, if your project group includes both an ASP.NET Web Service application and a Win32 VCL Form application, Delphi 2005 notes which of these projects is currently active, providing you with the designer and editor appropriate for each as you switch between your projects.

  One IDE, Multiple Languages

Delphi 2005 is more than just context-sensitive designers — it is a full multiple-language development environment. The native languages and debuggers that are included in Delphi 2005 are Delphi for Win32 development, Delphi for the Microsoft .NET Framework, and C# for the Microsoft .NET Framework.

While other IDEs support multiple languages, Delphi 2005 is unique in that it supports both multiple platforms and multiple languages transparently. For example, you can create a project group that includes a C# ASP.NET Web application, a Delphi for .NET Web Control class library, and a traditional Windows DLL (dynamic link library) written in Delphi Win32. Not only will the appropriate compiler and debugger be used for each project, based on its underlying language, but also the code editor features and Tool Palette snippets will expose the appropriate features as you navigate between the various projects.

Delphi 2005 can also support additional compilers, if you wish. For example, so long as you have the VB for .NET compiler installed on your workstation, you can create, open, edit, compile, and debug VB for .NET applications without ever leaving the Delphi 2005 IDE.

  The Structure Pane

The Structure pane is a context-sensitive view that provides you with detailed information about what ever is displayed in your main view. When you are using the code editor, the Structure pane displays the classes, types, interfaces, and other symbols in the current file, as shown in the following figure. (In Delphi 7, this view was called the Code Explorer.)

Hide image
F1

By comparison, when you are designing a VCL Form, the Structure pane displays the components that appear on your form, with the various nodes representing the containership of your controls. (In Delphi 7, this view was referred to as the Object Tree View.)

Hide image
F1

Not only does the Structure pane provide you with valuable insight into your projects, it also serves as a convenient tool for navigating the symbols and objects that you are using. When you are editing your code, double-clicking a symbol in the Structure pane takes you to the associated line of code in the editor. When you are designing a VCL Form, clicking an object selects it in the designer, permitting you to quickly change its properties or assign event handlers.

The Structure pane is also invaluable when there are errors in your code. When Delphi 2005's new Error Insight feature identifies problems in your source files, these appear automatically, as you type, in the Structure pane, permitting you to quickly navigate to the position in the code editor where problems exist. Error Insight is described in more detail in the "The Next Generation Code Editor" section of this guide.

  The VCL and VCL for .NET Floating Designer

Some developers who used Delphi 8 for the Microsoft .NET Framework wished for a "floating" VCL designer, like the one available in Delphi 7. Borland listened. For Delphi development of VCL and VCL for .NET applications, Delphi 2005 provides you with a choice between using the .NET-style embedded designer or the classic floating designer.

To enable the floating designer in Delphi 2005, select Tools | Options. Navigate to the VCL Designer node under Delphi Options, and uncheck the Embedded designer check box.

Hide image
F1

  The Tool Palette

When you work in a component-based environment like Delphi 2005, you typically make extensive use of design-time components, which are placed into the designer and configured using the Object Inspector. These components are available from the Delphi 2005 Tool Palette.

The Tool Palette is organized by component category. Which categories are displayed, and which components appear within them, is context sensitive, based on the type of project on which you are working. Furthermore, the Tool Palette permits you to controls its organization. You can change the position of a component within a Tool Palette category, as well as move a component to a different category, simply by dragging the component within the Tool Palette. You can even define your own custom categories into which you can drag your components.

Delphi 2005 includes a number of enhancements to the Tool Palette. These are discussed in the following sections.

  Enhanced Tool Palette Behavior

Delphi 2005's Tool Palette is better than ever. In addition to providing access to design-time components and code snippets, depending on whether you are working with a designer or code editor, the updated Tool Palette can also be used to create new projects, files, and objects. When you do not currently have a project open, the Tool Palette provides access to all of the wizards and templates of the Object Repository. Some of these are shown in the following figure.

Hide image
F1

When you are using the code editor, the Tool Palette now includes these same options in addition to code snippets, reusable pieces of code that you can drag into the code editor.

Selecting objects from the Tool Palette has also been enhanced, greatly improving the speed with which you can build forms and applications. Simply click the Filter current items button in the Tool Palette toolbar, or press Ctrl-Alt-P, and start typing the name of the object you want to select. As you type, the characters you've entered so far appear in the Tool Palette title bar, and a filtered list of matching objects appears below, as shown in the following figure. Press Enter when the item you want is selected.

Hide image
F1

You also have additional options for controlling the Tool Palette display. To see these options, select Tools | Options from Delphi 2005's main menu. Tool Palette configuration options are available under the Tool Palette node of the Options dialog box.

Hide image
F1

Finally, the Tool Palette in Delphi 2005 now supports true drag-and-drop placement of components into the designer you are working with. Previously, component placement with VCL Forms could be better described as click-and-click, though that technique also works in Delphi 2005.

  New VCL for .NET Components

For Delphi VCL-based development, the Tool Palette now includes a number of new controls for creating better using interfaces. These include a TButtonGroup, TCategoryButtons, and TDockTabSet. These components, which you can use in your Win32 and VCL for .NET applications, permit you to easily create interfaces similar to those used in Delphi 2005’s Tool Palette and the Structure pane. As you have probably already guessed, these new components are the same ones that Borland's engineers developed to build Delphi 2005's IDE.

In addition, VCL for .NET has been expanded to include even more Delphi VCL-compatible classes. These additional classes make it even easier than before to migrate your existing Win32 projects to the .NET framework.

For a complete list of the new components in Delphi 2005, see "What's New in Delphi 2005" in the Delphi 2005 help.

  The Object Inspector

Delphi 2005's Object Inspector, which you use to configure objects placed on your form at design time, has also been updated. Not only does the Object Inspector permit you to configure properties and events for the objects that you have placed into the designer, but you can also use it to control file names and get information about objects that you select in the Project Manager.

For example, select a file in the Project Manager, such as an .aspx file in an ASP.NET Web application, and the file path and file name will appear in the Object Inspector, as shown in the following figure.

Hide image
F1

The File Name property in the preceding figure is shown in an enabled font, indicating that you can edit the name of this file using the Object Inspector. Changing the file name here not only changes the name of the file displayed within the Project Manager, but since this file is a Delphi unit, the unit name changes as well. Of course, you can still rename a file the old fashioned way, by selecting File | Save As from Delphi 2005's main menu.

Other objects selectable within the Project Manager can also be viewed in the Object Inspector. For example, if you select one of the assemblies listed under the References node of a .NET project in the Project Manager, the Object Inspector displays details about that assembly, as shown in this next figure.

Hide image
F1

  The Upgrade Project Wizard

Because Delphi 2005 includes both Win32 and .NET compilers for the Delphi language, it can be used to create new Win32 applications as well as further the development of your existing Win32 projects that you created in Delphi 7 and earlier. You can also use Delphi 2005 to migrate your existing Win32 applications to VCL for .NET, the 100% .NET managed-code solution that maintains component and source code compatibility between Win32 and .NET development.

The Upgrade Project Wizard is a special utility that runs the first time you open a Win32 application in Delphi 2005. Using this utility, you can choose to continue the current project as a Win32 application, or you can convert it to a .NET application.

Hide image
F1

Once you made your choice using this wizard, Delphi 2005 will remember your selection. If you tell the Project Upgrade Wizard that you want to continue working with a Delphi project as a Win32 project, and at some later time decide to migrate it to VCL for .NET, simply delete your project's *.bdsproj file. After that, open the .dpr file in Delphi 2005. Once again, the Project Update Wizard will ask you to choose whether to continue working with the project as a Win32 project or to migrate it to VCL for .NET.

  Delphi 2005 Wizards

Wizards are small applets that help you to quickly create the projects, objects, and files that you use in Delphi 2005. For example, the ASP.NET Web Application Wizard creates for you the necessary web.config, global.asax, and initial .aspx file, and configures an IIS virtual directory into which these are placed, among other tasks. In short, wizards increase your productivity, getting you off to a fast start in the right direction. The following figure shows the Delphi 2005 object repository, displaying just a few of the many available wizards.

Hide image
F1

Delphi has always provided you with a rich collection of wizards that support almost every aspect of Windows development. For Win32 development, these include the Windows 2000 Logo Wizard, the DLL Wizard, the Automation Object Wizard, the Web Service Wizard, the IntraWeb Application Wizard, the Database Form Wizard, and the Thread Wizard. These are just a few or the dozens of powerful wizards that are available.

For Delphi for .NET and C#, you will find the ASP.NET Web Application Wizard, the Windows Form Application Wizard, ASP.NET Web Service Application Wizard, the Web Control Library Wizard, and many, many more.

Delphi 2005 includes Wizards that were previously found in Delphi 7, Delphi 8 for the Microsoft .NET Framework, and C# for the Microsoft .NET Framework. In addition, Delphi 2005 includes a number of new and improved wizards ¾ accelerating your development efforts even more. These include the updated New Component Wizard, the new DB Web Control Library Wizard, the ECO ASP.NET Application Wizard, the ECO Web Service Application Wizard, and the Satellite Assembly Wizard, just to name a few.

  Find in Files Enhancements

Delphi 2005 makes it even easier for you to search your project files by permitting you to group search results by file. To group search results by file, check the Group results by file check box in the Find Text dialog box.

Hide image
F1

The following figure shows what a grouped search result looks like. As you can see, each file in which the search string appears forms a base node in a tree view. Expanding the node for a given file lists the lines on which the located search string was found. You can then double-click a particular entry to go to that line of code in the code editor.

Hide image
F1

  Updated Support for International Characters

Delphi 2005's IDE has been upgraded across the board to support UTF-8 characters in all of its wizards, windows, dialog boxes, and panes.

  Message List Enhancements

Delphi 2005 uses the Message List pane to list compiler errors, warnings, and hints. You can now save the contents of the Message List pane by right-clicking in the Message List pane and selecting either Copy, to copy selected messages to the Windows clipboard, or Save, to save the Message List contents to a file.

  IDE Error Reporting

Borland's commitment to creating better software has lead to the development of a number of programs for reporting and fixing problems. One of the most recent of these is Quality Central, a Web-based application for submitting bug reports located at http://qc.borland.com.

With Delphi 2005, Borland has embedded an error reporting system directly into the IDE. This feature is called IDE Error Reporting. While Borland hopes that you never have to use it, if an exception is raised within the IDE, Delphi 2005 displays the Error dialog box. If you click the Details button, you see a detailed trace of the error.

Hide image
F1

Clicking the Send button displays the Send Report dialog box. Hide image
F1

Click the Next button to see the stack trace that will be submitted to Borland along with your error report. Click Next again to enter a description of what you were doing when the error occurred.

Hide image
F1

Click Next once more to optionally provide your Borland Developer Network (BDN) logon email address and password. Submitting your report using your BDN account permits you to easily follow up on your report using Borland's Quality Central. If you want to submit the report anonymously, check the Anonymous Report check box.

Click Next one final time to submit the error report.

  Import/Export Project from/to Visual Studio .NET

Do you currently have C# projects in Visual Studio .NET 2003, but need the advanced features offered by Delphi 2005? Don't worry. Importing these projects into Delphi 2005 is easy.

Simply select File | Open, and open the Visual Studio C# project file (*.csproj). The Delphi 2005 Import Visual Studio Project Wizard will ask you for the name you want to give to the imported project. From that point forward, you can use Delphi 2005's features to design, develop, compile, test, and deploy the application.

The following figure shows a C# project created in Visual Studio .NET 2003 being imported into Delphi 2005.

Hide image
F1

While the features of Delphi 2005 make it the preferred environment for .NET development, C# projects built in Delphi 2005 can be exported to Visual Studio if you need to share the results of your work with a VS-based developer. To do this, select Tools | Export to Visual Studio from Delphi 2005’s main menu. Note that this menu item is only available when the current project in the Project Manager is a C# project.

   The Next Generation Code Editor

Delphi 2005 continues Borland's heritage of providing developers with a world-class programming environment. To most developers, that also means a world-class code editor. And that’s exactly what you get in Delphi 2005.

In fact, for most developers, the updates that Borland has introduced to the code editor in Delphi 2005 will provide ample justification to upgrade from a previous version of Delphi or C# Builder. These features include refactoring support, SyncEdit, Error Insight, Help Insight, the History Manager, and much, much more. These new features are described in the following sections.

  Refactoring

Refactoring is the process of updating existing code to improve its readability, maintainability, and efficiency, without changing the essential behavior of the software. Common refactorings include providing more expressive names for variables, replacing duplicate code segments with a call to a common function that performs the same task, and replacing literal values with constants or resource references.

Delphi 2005 includes a number of impressive refactorings. These include symbol renaming, method extraction, variable and field declarations, and resource refactorings.

  Symbol Renaming

Symbol renaming permits you to change all instances of a symbol's name throughout your project. Unlike a search-and-replace feature, symbol renaming respects the context in which the symbol name appears. Symbols that can be renamed using this refactoring include class and interface names, properties, methods, functions and procedures, as well as variables and constants.

To perform a symbol renaming refactoring, select the symbol whose name you want to change in the code editor, and select Refactoring | Rename. Use the Rename dialog box to define a new name for your symbol.

Hide image
F1

If you leave the View references before refactoring option checked, Delphi 2005 displays the Refactorings pane, which lists all of the instances within your code where the change will be applied.

Hide image
F1

Click the Refactor button on the Refactoring pane toolbar to apply the changes. Alternatively, you can choose to remove one or more of the refactorings before applying them, or even cancel the refactoring altogether.

  Variable and Field Declarations

The Declare Variable and Declare Field options on the Refactor menu permit you to quickly create a local variable or member field declaration. This option is available with Delphi code, but not with C# projects. (This feature is not needed in C# since fields can appear almost anywhere within a C# class. By comparison, in Delphi variables must appear in a var block, and member fields must appear in a type block.)

To insert a local variable or member field, select the symbol name that you created in the code editor, and select Refactor | Declare Variable or Refactor | Declare Field (or press Ctrl-Shift-V or Ctrl-Shift-D, respectively). If you select Declare Variable, the Declare Variable dialog box is shown.

Hide image
F1

You use the Declare Variable dialog box to change the variable name, set its data type, make the variable an array type with a specific dimension, or to initialize the newly created variable to a specific value. Click OK to create the local variable, and initialize its value (if you chose that option).

If you select Declare Field, the Declare New Field dialog box is displayed. You use this dialog box to set the name and data type of the new field, to declare it as an array of a given dimension, and to define its visibility within the associated class. When you click OK, the newly named field is created in the selected section of the class within whose method the symbol is located.

Hide image
F1

  Resource Refactoring

Resource refactorings are used in Delphi code to convert string literals into resourcestring block entries, replacing the original literal with the resource string symbol. (There is no resourcestring block in the C# language.) Using resource strings instead of string literals is particularly valuable when a specific string literal is used repeatedly, as well as when you need to create localized (language and/or culture specific) versions of your application.

After placing your cursor within a string literal in the Delphi code editor, select Refactor | Extract Resource String. Use the Extract Resource String dialog box to modify the string and to change the default name for the resource symbol. When you click OK, the string literal is replaced with the resource symbol, and the named symbol is inserted into a resourcestring block in the associated unit's interface section.

Hide image
F1

  Extract Method Refactoring

Most developers think of method extraction when they think of refactoring. Method extraction involves converting one or more lines of code into an independent method call, replacing those lines with an invocation of the extracted method.

In Delphi 2005, method extraction refactoring is only available for the Delphi language.

Method extraction is particularly useful when the same or similar lines of code appear repeatedly in your project. By extracting those lines to a separate method, replacing each of the repeated instances with an invocation of the method, you greatly enhance your code's maintainability by creating a single location where changes to those lines of code, if desired, need to be implemented.

To perform a method extraction refactoring, select the lines of code that you want to extract to a method, and then select Refactor | Extract Method. Use the Extract Method dialog box to define a name for the new method, as well as to examine the code that will be placed inside of this new method.

Hide image
F1

Delphi 2005's extract method refactoring is intelligent, with respect to variables, properties, and objects referenced within the code being extracted. For example, since the code in the preceding figure includes a reference to the Disposing property of the method's class, the value of this property is passed by value to the refactored code. By comparison, if the code actually made a change to the value of a variable that needs to be passed into the refactored method, the associated parameter would be passed by reference (using the var keyword).

  Import Namespace (C#) and Find Unit (Delphi)

Although not exactly a refactoring, the Import Namespace and Find Unit options under the Refactor menu permit you to quickly locate and import the namespace associated with a particular symbol. If you are coding in C#, you select Refactor | Import Namespace. Delphi developers select Refactor | Find Unit.

After selecting this option from the Refactor menu, the displayed dialog box lists all of the classes in all of the namespaces available to the environment you are working in. For example, if you are creating a Delphi .NET Windows Forms application, the namespaces of the FCL and RTL for .NET (the .NET version of the Delphi runtime library) are available. Delphi VCL for .NET developers will find the VCL for .NET namespaces as well.

Hide image
F1

By comparison, if you are creating a Delphi Win32 application, the various units of the VCL and RTL are listed. Type the name of the class that you want to be able to access in the Search field. As you type, the Matching Results list is filtered to include only those classes, and their associated namespaces, whose names match what you've typed so far.

Select the name of the class whose namespace you want and click OK. If you are working in Delphi, you can also specify whether the namespace will be added to your interface or implementation section uses clause.

Hide image
F1

  SyncEdit

SyncEdit is a new feature in Delphi 2005 that provides support similar to symbol renaming refactoring. Unlike symbol renaming, however, SyncEdit performs localized renaming of symbols for a selected code block only. This is a powerful capability and one of the most popular of the new features with developers.

SyncEdit becomes available anytime you select a code block that includes at least two instances of the same symbol name. For example, consider the following figure, which depicts a selected code block that includes more than one reference to a local variable named DataTable1 (as well as DataSet1, DataAdapter1, Connection1, and the Create method).

Hide image
F1

The SyncEdit icon appears in the left gutter of the editor window, indicating that synchronized changes to the selected code block are available. To enter the SyncEdit mode, you either click this icon or press Shift-Ctrl-J.

Once you enter the SyncEdit mode, the duplicate symbols are identified, and the symbol selected for synchronized editing appears highlighted (with the duplicates being displayed enclosed in boxes). If you want to edit a symbol other than the one selected by default, press the Tab key until the symbol you want to SyncEdit is selected.

Hide image
F1

After selecting the symbol to edit, begin typing. The name of the selected symbol, and its duplicates, are updated as you type. The following figure shows the name of the DataTable being changed to CustTable. (The edit is being performed on the first instance of DataTable1, which appeared in the var declaration of this method.)

Hide image
F1

SyncEdit is a great productivity tool when you are writing functions, procedures, and methods, in that this feature is so easy to use. There are, however, important differences between SyncEdit and symbol renaming refactorings. SyncEdit is lexical, so it works with comment lines as well as compilable code, unlike symbol renaming refactorings, which work only on actual symbol references. Likewise, symbol renaming refactoring extends its reach into descendant classes, as well as to resource files (such as VCL and VCL for .NET form files). SyncEdit only applies to the currently selected code block.

  Error Insight

Error Insight, which makes its debut in Delphi 2005, provides you with a service that can be roughly described as spell checking and grammar checking for programmers. As you write your Delphi or C# code, the IDE actively evaluates your work, identifying the symbols, keywords, and directives that you use, looking for syntax and semantic errors that the compiler cannot resolve. When Error Insight locates an error, it identifies the problem by underscoring the offending text with red squiggly lines, similar to how Microsoft's Word identifies words not in its dictionary.

Hide image
F1

When you pause your mouse pointer briefly over a symbol that Error Insight does not recognize, Error Insight displays a hint window with information about the identified error.

In addition to the Error Insight features available in the code editor, the problems located by Error Insight also dynamically appear in the Structure pane, under the Errors node, and disappear as they are corrected. The following figure shows the Structure pane with a number of identified errors.

Hide image
F1

In the example shown in the preceding figures, adding the Borland.Vcl.Registry unit (for the TRegistry class) and Borland.Vcl.Windows (for the HKEY_LOCAL_MACHINE constant) to this unit's uses clause allows Error Insight to see the various symbols that it identified as problems. Once these two units are added to the uses clause, both the Structure pane and the code editor are updated, indicating that no problems are detected in this code.

You can configure Error Insight from the Code Insight node of the Options dialog box. Display this dialog box by select Tools | Options from Delphi 2005's main menu.

  Help Insight

Another new Code Insight feature appearing in Delphi 2005 is Help Insight. Help Insight provides you with information about the classes, interfaces, methods, properties, and fields that appear in your code, without you ever having to leave the code editor.

To access Help Insight, briefly pause your mouse pointer over a symbol in the code editor. After a moment, a hint window appears, displaying information about the symbol.

Hide image
F1

In many instances, Help Insight includes one or more links within the hint window. Clicking one of these links may drill down into the help, displaying an additional hint window with information about the link you clicked. Alternatively, clicking a link may take you to the line of code where the clicked symbol is defined.

Help Insight is also available from the windows displayed by Code Insight, including the Class Completion and Argument Value List windows. When a Code Insight window is active, select an item in the Code Insight window to show the Help Insight for that item. For example, in the following figure Help Insight is displaying information about the BeginTransaction method of a SqlConnection object. This help became available after BeginTransaction was selected in the Code Completion window.

Hide image
Click to see full-sized image

You can configure Help Insight from the Code Insight node of the Options dialog box.

  The History Manager

One of the more exciting additions to the Delphi 2005 code editor is the History Manager. The History Manager, which you display by clicking the History tab when a source file is active in the code editor, permits you to view changes to your source files over time, to view comments about specific versions of your source code, as well as to view the differences between the various saved versions of your files and to easily revert to any backup state or checkin.

By default, the History Manager transparently maintains local copies of your source files in a folder named __history under your project directory each time you save your changes. This feature is called local file backup, and you use the Options dialog box to configure how many versions of your local backup to keep. Delphi 2005 maintains the last 10 saved versions of each source file, by default. Depending on your available hard disk space, you may want to increase the number of backups that Delphi 2005 maintains.

If you are using Borland’s StarTeam version control server, the History Manager maintains StarTeam checkins as well. Using this feature, you can not only view changes that you have made to the source files, but also compare your changes with those implemented by other developers working on the StarTeam-managed project. StarTeam also permits you to track changes even after you have changed a file's name. In short, the History Manager provides you with a convenient and powerful interface to the robust StarTeam project asset management system.

It's worth noting that the History Manager also works with the DFM files of VCL and VCL for .NET applications. DFM files are used in those applications to persist information about the properties of the objects that appear on your forms, data modules, and frames. As a result, the History Manager permits you to view, manage, and restore changes made to your form designs using the same tools as those used on Delphi code files.

There are three panes available within the History Manager. These panes are named Content, Info, and Diff. Each of these panes is described in the following sections.

  The Content Pane

You use the Content pane to review the contents of your saved source files, and optionally revert to a previously saved version. When you select a specific backup or the current saved version of the file, the contents of that file are displayed in the code area. In addition, the file name and the date last saved appear in the History Manager's status bar.

Hide image
Click to see full-sized image

Use the code area to view the contents of the selected file. If you want, you can use the code area to select and copy (Ctrl-C) lines of code that you want to paste elsewhere within your project (or even into other projects).

If you want to revert your code to one of the previous saved versions, select the saved backup that you want to revert to and click the Revert to previous version button in the History Manager toolbar.

  The Info Pane

You use the Info pane to view comments and notes associated with a particular version of your source file. If you are using StarTeam to manage your History Manager contents, these comments are linked to your StarTeam backups. If you are using local backups, these comments are generated by Delphi 2005 and cannot be modified. Some operations, such as refactorings, write information into the Info pane of the History Manager.

Hide image
Click to see full-sized image

  The Diff Pane

For most developers, the Diff pane offers the most valuable feature of the History Manger. The Diff pane provides insight into the differences between the multiple versions of your source code, including comparisons between the current edit buffer and saved source files.

Select one of the saved versions of your source file from the Differences From: list on the left side of the Diff pane, and either the contents of the current edit buffer or one of the other saved versions from the To: list on the right side. The difference view is displayed in the code area, with the newer code versions identified with a plus sign (+) in the left gutter, and the older versions identified with a minus (-) sign in the gutter.

The following figure depicts changes between the current version of the file in the edit buffer and one of the saved local backups.

Hide image
Click to see full-sized image

  Code Navigation Enhancement

Code navigation is a feature of Delphi 2005 that permits you to easily move between sections of your code. For example, by pressing Ctrl-Shift-UpArrow (or Control-Shift-DownArrow), you can move effortlessly between a method name in a Delphi class declaration to the associated implementation of that method.

Delphi 2005 introduces a small but valuable enhancement to code navigation in Delphi code, permitting you to move between your interface and implementation section uses clauses, as well as between your unit's initialization and finalization sections, using Ctrl-Shift-UpArrow.

Code navigation is not necessary in C# projects, as the associated modules in C# do not have a two-part structure, as is the case with Delphi units.

  Toggling Code to/from Comments

Delphi 2005 introduces a new feature that permits you to quickly comment and uncomment a selected code block. To comment one or more consecutive lines of code, select the code in the code editor, right-click, and then select Toggle Comment from the displayed context menu (or press Ctrl-/). When you do this, Delphi 2005 places the single line comment characters (//) at the start of each of the lines in the selected block.

To uncomment one or more consecutive lines, select those lines and press Ctrl-/, or right-click and select Toggle Comment. Delphi 2005 will respond by removing the single-line comment characters from each selected line in the block. The single-line comment characters do not have to be in the first column of the code editor for Delphi 2005 to remove them.

  Persistent Bookmarks

Bookmarks are special tags that you place within a source file to enhance your navigation within that file. You place a bookmark by press Ctrl-Shift, followed by a single digit, from 0 to 9. Once placed, the bookmark appears in the left gutter of the code editor using a glyph that represents the digit.

Once a bookmark has been placed, you can quickly navigate to that bookmark within the code editor by pressing the Ctrl key followed by the digit used to place the bookmark. For example, if you have previously placed a bookmark using Ctrl-Shift-1, and subsequently navigate to a different area of your code file, you can instantly return to the bookmarked line in your source code by pressing Ctrl-1.

Delphi 2005 now supports persistent bookmarks. If persistent bookmarks are enabled, a placed bookmark will remain in the source code until you specifically remove it. This means that you can place a bookmark in one editing session, and that bookmark will still be there the next time you open that source code file in Delphi 2005.

In order to enable persistent bookmarks, check the Project desktop check box under the Autosave options group on the Environment Options page of the Options dialog box. You display the Options dialog box by selecting Tools | Options from Delphi 2005's main menu.

  J2EE and CORBA to .NET Integration with Janeva

Janeva is Borland's middleware solution for using J2EE (Java 2 Enterprise Edition) Enterprise JavaBeans and CORBA (common object request broker architecture) objects from your Delphi 2005 applications. With Janeva, you can leverage your existing enterprise-level objects, calling them from your Web-enabled or workstation client .NET applications.

To enable access to a J2EE or CORBA object from your Delphi 2005 application, select the Project menu on Delphi 2005's main menu, or right-click the current project in the Project Manager, and select either Add J2EE Reference or Add CORBA Reference.

Hide image

Use the displayed dialog box to select the Java .jar or .ear file, or the CORBA IDL (interface definition language) file. If you select a Java archive, for example, Delphi 2005 then permits you to choose which of the contained Enterprise JavaBeans you want to use, as shown in the following figure.

Selecting OK generates a proxy class that you use to make calls to the Java server at runtime.

  User Selectable File Encoding

You can now choose how Delphi 2005 will encode your source files. Your options include ANSI, Binary, UTF8, and so on.

To set the file encoding for the current source file in the editor, right-click in the editor and select File Format from the context menu. Select the encoding you want to use from the displayed menu.

Being able to select the source file encoding is particularly valuable when you are writing source files using non-US locales. For example, source files encoded using UTF-8 will correctly maintain the identity of the individual characters even when opened in a different locale. By comparison, special characters in a source file may change if the source file is encoded in ANSI and then opened with a different ANSI codepage.

   The VCL for .NET

The Delphi visual component library for .NET (which for the purpose of this discussion, includes the runtime library for .NET, or RTL for .NET), is a 100% .NET managed code equivalent of the Delphi VCL for Win32. Several features of the VCL for .NET are notable. For one thing, VCL for .NET is the largest, 100% managed collection of classes, types, and functions for the .NET framework outside the .NET framework class library itself. And it's only available in Delphi 2005 (or its immediate predecessor, Delphi 8 for the Microsoft.NET Framework).

The second characteristic of the VCL for .NET is its remarkable compatibility with the Win32 versions of the VCL. In fact, you use this compatibility to migrate your Win32 Delphi code to .NET with little or no effort.

There are several updates to the VCL for .NET added to Delphi 2005. These are described in the following sections.

  Virtual Library Interfaces

Delphi provides extensive support for interoperability between Win32 and .NET applications, including COM interop through runtime callable wrappers (RCWs) and platform invoke (PInvoke). With Delphi 2005, this support has been advanced through the support for virtual library interfaces (VLI). Virtual library interfaces permit you to call routines in Win32 DLLs from your .NET applications much more easily than the mechanism provided by .NET's PInvoke.

Normally, managed code in the .NET framework can call routines in unmanaged libraries through the .NET platform invoke service, or PInvoke. With PInvoke, you import the exported routines of an unmanaged DLL by using the [DLLImport] attribute to identify the DLL in which the function is located, as well as other characteristics of the exported function.

There are several drawbacks to using PInvoke. First, using the [DLLImport] attribute you cannot resolve the DLL name or location (path) at runtime. Second, if the specified routine in the DLL cannot be loaded, for whatever reason, a runtime exception is raised.

Third, the [DLLImport] attribute is somewhat verbose and repetitive, especially when you have many routines that you are importing from a single DLL.

Consider the following two functions, which are implemented and exported from a Win32 DLL created using Win32 Delphi:

function ConvertCtoF(CentValue: Integer): Integer; stdcall;
function ConvertFtoC(FahrValue: Integer): Integer; stdcall;

A unit that imports these routines using PInvoke has, at a minimum, an implementation block that looks something like the following (assuming that these routines were exported from a DLL named Win32DLL.dll):

function ConvertCtoF; external;
[DllImport('Win32DLL.dll', CharSet = CharSet.Auto,
EntryPoint = 'ConvertCtoF')]
function ConvertFtoC; external;
[DllImport('Win32DLL.dll', CharSet = CharSet.Auto,
EntryPoint = 'ConvertFtoC')]

With virtual library interfaces, importing routines from an unmanaged DLL is easier, is less prone to raising exceptions, and permits your code to resolve the name and/or location of the DLL at runtime. There are three steps to importing one or more routines from an unmanaged DLL using virtual library interfaces. These are:

Adding the Borland.Vcl.Win32 namespace to your uses clause

Creating an interface declaration where each method in the interface maps to one of the routines exported from the DLL

Calling the Supports function from the Borland.Vcl.Win32 unit, passing to it the name of the DLL (including an optional path if the DLL is not located in a location where Windows will find it), the Interface you created in the preceding step, and a variable of that interface type

If the Supports function determines that the methods of your interface map to functions exported from the named DLL, the variable you pass in the third parameter of the call to Supports will point to an object that implements the interface you passed in the second parameter. You can then use this object reference to execute the unmanaged routines of the DLL.

If one or more of the methods of the interface are not exported by the named DLL, or the named DLL does not exist or is somehow compromised, Supports returns a Boolean false without raising an exception.

Here is a sample interface that declares the two exported functions of the unmanaged DLL example used earlier in this section:

type
IWin32DLLInt = interface
function ConvertCtoF(CentValue: Integer): Integer;
function ConvertFtoC(FahrValue: Integer): Integer;
end;

If Win32DLL.dll is located in the mylib subdirectory of the application's executable, the following code returns an implementation of IMyWin32DLL, after which one of the methods (ConvertCtoF) of the returned object is executed:

var
MyDLL: String;
MyWin32DLL: IWin32DLLInt;
begin
MyDLL := ExtractFilePath(Application.ExeName) +
'\mylib\Win32DLL.dll' ;
if not Supports(MyDLL, IWin32DLLInt, MyWin32DLL) then
MessageBox.Show(self, 'Could not load Win32DLL.dll')
else
NewInt := MyWin32DLL.ConvertCtoF(100);

  Support for Partially Trusted Callers

The VCL for .NET assemblies now support partially trusted callers. A partially trusted caller is an application that does not reside on the same workstation as a managed assembly that it calls.

For example, an .exe being executed from a network share or from a URL is a partially trusted caller. By default, the .NET security model prevents a partially trusted caller from invoking unmanaged code, such as that in the Windows API, unless that caller includes the appropriate declarations and checks.

The Delphi 2005 assemblies of the VCL for .NET now include the additional security declarations and checks that permit the VCL for .NET to be called from a partially trusted caller without violating .NET security.

   The Delphi Compilers

Borland compilers are legendary for their speed and compatibility, and this legacy continues with Delphi 2005. Actually, Delphi 2005 ships with three compilers. One of these compilers, the C# compiler, is licensed from Microsoft. Consequently, C# applications you build in Delphi 2005 generate the same intermediate language (IL) code as those built with Visual Studio.

The other two compilers are Delphi compilers, one for compiling traditional 32-bit Windows executables and the other for generating IL for the .NET Framework. Both of these compilers have received significant updates in the Delphi 2005 release.

This section begins with a discussion of features added to both the Win32 and the .NET versions of the Delphi compilers. Later in this section, you will learn about the new features that are specific to one or the other of these compilers.

  Updates for Both Win32 and .NET Delphi Compilers

Several new features have been added to both of Delphi 2005’s Delphi compilers. These most significant of these include the new for…in loop and Unicode support. These new compiler features are described in the following sections.

  The For…In Loop

The Delphi language has been updated to include a new looping control structure similar to the C# foreach keyword. In Delphi, this new loop is referred to as a for…in loop. Unlike traditional for loops in Delphi, the for…in loop does not require an ordinal control variable. Instead, the for…in loop systematically retrieves a reference to the next object in a collection of like objects.

For example, the following code segment can be used to iterate through the DataRows of a DataTable's Rows property (this property is of the type DataRowCollection):

var
Row: DataRow;
begin
//…
for Row in MyDataTable.Rows do
ListBox1.Items.Add(Row[0].ToString);

For the .NET Delphi compiler, for…in can be used with any object that satisfies at least one of the following conditions: it implements the IEnumerable interface, has a public GetEnuermerator function, or is an array, set, or string. For the Win32 compiler, for…in can be used with any class that has a public GetEnumerator function, or is an array, a set, or a string. Classes that implement a GetEnumerator function include TList, TCollection, TStrings, TMenuItem, TFields, to name a few.

  Support for Unicode and UTF8 Formats

Both of Delphi’s compilers can now compile UTF8 and Unicode source files. Previously, only ANSI source files were supported. For the Delphi for .NET compiler, this feature supports CLS (common language specification) standard Unicode identifiers in both metadata and in source code.

  The Delphi for .NET Compiler

Borland's Delphi for .NET compiler made its first debut with the release of Delphi 8 for the Microsoft .NET Framework. In addition to the updates listed in the preceding section, this compiler has received a number of updates that apply specifically to .NET applications. These include a revision to how namespaces are created and managed, forward-declared record types, and support for weak packaging in VCL for .NET applications. The updates to the Delphi for .NET compiler are described in the following sections.

  Delphi Code and Namespaces

The biggest change to the .NET compiler is in how it generates namespaces for the symbols defined in your units. Under the previous version of the compiler, the unit name was the namespace.

For some developers, particularly those accustomed to using classes defined in C#, the namespaces created by Delphi appeared awkward. Specifically, these namespaces revealed the physical structure of the underlying code, which is irrelevant from the perspective of the person using your classes, and can be distracting.

The Delphi 2005 compiler takes a new approach to namespace generation, allowing multiple units, and even multiple applications, to contribute to a common namespace, if desired. At the same time, it is just as easy to make each unit contribute to a separate namespace.

Here is how it works. If your unit names do not use dot notation, the unit name is the namespace. This is how it worked before.

If a unit includes a multipart name, using dot notation, the namespace is defined by dropping the last part of the unit name. For example, if a unit has the name YourCompany.Data.Unit1, the classes within that unit will reside in the YourCompany.Data namespace. Classes that appear in the YourCompany.Data.Unit2 and YourCompany.Data.Unit3 units will be in the YourCompany.Data namespace as well.

Global variables, constants, functions, and procedures declared in Delphi code represent something of a challenge, in that .NET requires all declarations to be associated with a class. Therefore, the global symbols of a Delphi unit named YourCompany.Data.Unit1 are implemented in .NET metadata as members of a class named Unit1 within the namespace YourCompany.Data.Units.

How Delphi symbols appear in .NET metadata has no effect on your Delphi source code. You only need to consider how your Delphi code will appear in the .NET metadata for the portion of your code that you want developers using other .NET languages to use. In general, you should avoid using global variables, global constants, or global procedures and functions when writing Delphi code that you intend to be used by other .NET languages.

  Support for Weak Packaging in VCL for .NET Applications

A runtime package in the VCL for .NET is a managed .NET assembly ¾ it contains declarations that the application can load and use at runtime. Under normal circumstances, if you compile a VCL for .NET application to use a runtime package, you are required to deploy that package, just as you are required to ensure the deployment of all assemblies (DLLs) that are referenced in your application.

Weak packaging of a unit addresses a problem that arises when a runtime package contains one or more units that statically link to an external DLL, in particular, a DLL that is not commonly available. Under normal conditions, this situation requires that you deploy both the runtime package and the DLL.

Consider the Microsoft DLL PenWin.dll for pen device input, which is not distributed with Microsoft operating systems. The PenWin unit in Delphi statically links to the DLL PenWin.dll. If your unit uses PenWin, and includes calls to one or more functions in the statically linked PenWin.dll, adding your unit to a runtime package without weak packaging would require that the PenWin.dll be available from any application that loaded that runtime package. By making this unit weakly packaged, only applications that actually call PenWin.dll functions will require PenWin.dll.

Weak packing permits an application to link a non-packaged version of the unit into the executable instead of using the runtime package that contains this unit. As a result, applications that need the features of the weakly packaged unit will link the non-packaged version of the unit (that stored in the compiler-generated DCPIL file), and as a result, require the DLL. Applications that do not use the unit will not require the DLL, even if they are compiled to use the package that contains the weakly packaged unit.

Weak packaging has been available for some time in the Delphi Win32 compiler. Weakly packaged unit semantics are now supported by the Delphi for .NET compiler.

  Forward Declared Record Types

Record types can now be forward declared in Delphi VCL for .NET and FCL applications. A forward declared record instructs the compiler to recognize the record as a valid type, even though its formal declaration appears later in the same type block.

Forward declared record types permit two type declarations, specifically records,