Introduction to Delphi for .NET and the New IDE

secrettownpanamanianΚινητά – Ασύρματες Τεχνολογίες

10 Δεκ 2013 (πριν από 2 χρόνια και 10 μήνες)

57 εμφανίσεις

Introduction to
Delphi for .NET
and the New IDE
Programs, Units,
and Namespaces
The Delphi
• Delphi for .NET—a Bigger
• Introduction to the Integrated
Development Environment
Introduction to Delphi
for .NET and the New IDE
orland’s Delphi for .NET has been a long time coming—at
least in the hearts and minds of the many loyal Delphi devel-
opers in the world. Borland has answered the call to create an
integrated development environment for building .NET appli-
cation in Delphi, and it has answered it well. This chapter
introduces you to the Delphi for .NET product and how the
new IDE enhances productivity.
Delphi for .NET—a Bigger Picture
So what exactly is Delphi for .NET? Delphi for .NET is one
component of Borland’s broad vision for how developers
create business solutions. This vision has to do with providing
the full Application Lifecycle Development (ALM) process
onto the desks of development teams, giving them the full
scope of tools needed to develop applications. These tools
form a suite of products around this ALM concept, giving
them what they need to define, design, develop, test, deploy,
and manage software projects.
This book is focused on the “develop” stage of ALM, and
Delphi for .NET is just one of the tools that Borland provides
to serve that purpose. Nevertheless, because it is a good idea
to know how Delphi for .NET fits into the grand scheme, it is
recommended that you read the various whitepapers and arti-
cles on both the Borland’s main site and community site.
Borland’s Web site is
. The community
site is
. My site that will be dedi-
cated to Delphi development and particularly .NET develop-
ment in Delphi is
. This site will
also be the location from which you can obtain code updates
and errata sheets on this book.
04 0672324431 CH03 4/19/04 2:22 PM Page 23
Introduction to the Integrated Development
Environment (IDE)
Much like previous versions of Delphi, its IDE is a powerful environment through which
you design and develop applications. It includes the various tools needed to enable you to
do this; plus it is extensible, enabling third-party vendors to enhance the IDE capabilities.
This chapter goes over the key components of the IDE.
This will be the only chapter in which I discuss how to use the IDE. In fact, in much of the code in
this book, I make property assignments programmatically rather than setting them within the IDE.
I do this so that it is clear what assignments have been made to the various properties. Normally,
you would make such assignments using the IDE’s Object Inspector. For further tips on IDE usabil-
ity, you can visit
, where I will periodically post tutorials on using
Delphi for .NET.
The main components to the Delphi IDE are
• Welcome Page
• Main Form
• Designer Surface
• Forms
• Tool Palette/Code Snippets
• Object Inspector
• Code Editor
• Project Manager
• Data Explorer
• Code Explorer
• To-Do List
• Object Repository
This chapter discusses each of these components and then gets you started with your first,
simple Delphi for .NET application.
Welcome Page
The Welcome page is the first thing you see when the Delphi IDE is started (see Figure 3.1).
This page serves as more of a quick launch center from which you can create new projects,
open recent projects, and access various resources on Delphi for .NET.
If for some reason you lose the Welcome page, you can redisplay it by clicking View, Welcome Page.
CHAPTER 3 Introduction to Delphi for .NET and the New IDE24
04 0672324431 CH03 4/19/04 2:22 PM Page 24
FIGURE 3.1 Welcome page.
Note that the Welcome page has an embedded Web browser. Therefore, you can type a valid
URL into the URL combo to launch the Web site that you entered.
You can modify the
file in the Welcome Page directory to customize your Welcome
page—including your own links—change the shown picture, and so on.
The Designer is the area of the IDE that you see when you create either a new Windows Form,
Web Form, or VCL Form application shown in the center pane and you have clicked the Design
tab at the bottom of that pane (see Figure 3.2). The designer is the area where you perform your
visual design within the IDE. You can drag and drop components from the Tool Palette onto
your forms to visually design your applications. When working with VCL Forms, the designer
looks and behaves differently. For instance, you’ll notice that the right-click menu is different.
Some components are visual, whereas others are not. When you place visual components
on a form, such as a
, it is placed exactly where you positioned it on the form (Figure
3.2). Nonvisual components, such as the
, are positioned on
the Component Tray, which is the bottom portion of the Designer (see Figure 3.2). Such
components are only visible at design time so that you can select them to modify their
properties. Within the Designer’s status bar, you’ll see information about the status of the
file on which you are working such as whether it has been modified. You’ll also see your
cursor position and whether the editor is in insert or overwrite mode. You’ll also see the
Macro recording buttons on the status bar, which is discussed momentarily.
Introduction to the Integrated Development Environment (IDE) 25
04 0672324431 CH03 4/19/04 2:22 PM Page 25
FIGURE 3.2 Designer.
When working within the design, you will want to make sure to take advantage of some of
the features the IDE contains to enhance your productivity. Here are just a few:
• Locking Control—When you have positioned controls on the form the way you want
them, it’s often a good idea to lock them in place so that you don’t accidentally
move them as you select them with the mouse. To do this, simply right-click to
invoke the local menu and select the Lock Controls option. This locking is per form.
Also, the VCL designer only has a global Edit, Lock Controls for all forms.
• Tab Order—Something often forgotten is to set the tab order of controls. You can
examine the tab order of controls on your form by right-clicking to invoke the local
menu and selecting Tab Order. You can adjust the tab order of each control by click-
ing with your mouse anywhere on the control containing the tab order number.
• Be sure to take advantage of the Align, Position and Spacing toolbars to arrange
controls on your form. These toolbars become enabled when you have multi-selected
controls on the form.
• Docking—The IDE allows you to reposition/doc the various windows almost wher-
ever you want. This great feature enables you to adjust your work space as you like.
• Layouts—There are three predefined desktop layouts: Default,Classic (for those of
you who prefer the classic Delphi undocked layout), and Debug. The Default layout
CHAPTER 3 Introduction to Delphi for .NET and the New IDE26
Object Inspector
Main Form/Main Menu
DesignerComponent TrayStatus Bar
Tool Palette/Code Snippets
Project Manager
04 0672324431 CH03 4/19/04 2:22 PM Page 26
is shown in Figure 3.2. Figure 3.3 depicts the Debug layout, which shows various
debugging windows (Call Stack, Watch List, and Local Variables). The IDE switches to
the Debug layout whenever you start debugging an application. You can change and
save your own custom layouts as well.
• Customizing the File Menu—You can now customize the File, New menu to add
items that you frequently need to create. For instance, if you frequently need to
create Web Forms, you can add a WebForm to the File, New menu directly so that
you don’t have to launch the Object Repository from which you would normally
select this form.
Introduction to the Integrated Development Environment (IDE) 27
FIGURE 3.3 IDE Debug layout.
Forms are the main GUI entities that you create. They can be a window or dialog with
which the user interacts or a Web page. In Delphi for .NET, you can work with three types
of forms: Windows Forms, Web Forms, and VCL Forms.
Windows Forms enable you to use the classes within the .NET Framework to create func-
tionally rich, Managed GUI applications. You create a Windows Forms application by
selecting File, New, Windows Forms Application from the main menu. The IDE will then
present you with a Windows Form surface on which you place the various user-interface
controls from the tool palette to design the main form of the application. Typically, your
applications will consist of numerous Windows Forms. This book uses many examples
built upon Windows Forms.
04 0672324431 CH03 4/19/04 2:22 PM Page 27
Web Forms are the building blocks of ASP.NET Web applications. To create Web Forms,
select File, New, ASP.NET Web Application from the main menu. The IDE will then present
you with the Web Form designer, which is your workspace for your Web site pages. Part V,
“Internet Development with ASP.NET,” covers developing ASP.NET applications in detail.
VCL Forms are similar to Windows Forms in that they give you the tools and classes
required to build managed GUI applications. However, VCL Forms make use of Borland’s
own set of native .NET classes. VCL Forms, being built on Borland’s VCL framework, also
enable you to easily port existing Win32 applications to managed .NET applications.
Through VCL.NET, you will be able to create applications that target both the managed
.NET runtime and native Win32. To create a VCL Forms application, select File, New, VCL
Forms Application from the main menu. The IDE will present you with a form design
surface onto which you can place components from the Tool Palette to build functionally
interactive applications.
The Mono project is an effort well under way to create an open source .NET runtime for the Linux
Operating System. The goal of Mono is to be capable of running any managed assembly, and this
includes Delphi assemblies. Theoretically, because of the Wine project used to emulate Win32 on
Linux, there is hope to run VCL for .NET apps as is on Linux/Mono/Wine. As of now, this is not
realized. You can find out about the Mono project at
Tool Palette/Code Snippets
By default, the Tool Palette is located at the lower-right pane (refer to Figure 3.2). Its
contents depend on which view you happen to be working in. If you are working with the
Designer display, the Tool Palette contains the various components that you can add to
your form either by dragging and dropping them onto the form or by double-clicking
them. The list of available components depends on what kind of file you are editing (Win
Form, Web Form, VCL Form, or HTML file, for instance). If you are working in the Code
Editor, the Tool Palette contains a list of code snippets.
Code snippets are small blocks of reusable code. You can add your own code snippets to
the Tool Palette. Additionally, you can categorize the arrangement of your code snippets.
To add a category, simply right-click within the Tool Palette and select Add New Category.
Enter a category name and click OK. To add code from the code editor to your list of code
snippets, highlight your code, press the Alt key, and drag onto the Tool Palette. To add
code snippets to a new category, you must first add them to the default Code Snippets
category. Once added there, they can be dragged to a custom category. The order is
Drag the code to the default Code Snippets category.
Right-click to Add New Category.
Alt+Drag the new snippet from Code Snippets to your new category.
Also, an empty category will be removed when the Tool Palette loses focus.
CHAPTER 3 Introduction to Delphi for .NET and the New IDE28
04 0672324431 CH03 4/19/04 2:22 PM Page 28
Object Inspector
Through the Object Inspector (refer to Figure 3.2), you modify the properties of compo-
nents and attach event handlers to these components. This allows you to specify at design-
time various attributes that affect the visual appearance and behavior of components. For
example, after placing a Label component on a Windows Form, you can change its
property to something more specific and its font color to red. This is done in the Properties
Page of the Object Inspector. The Events page is where you attach code to various events of
each component. For example, a Button component has a
event that fires when the
user clicks the button. By double-clicking in the edit portion of the Object Inspector for
that event, the IDE automatically creates the event handler for you and places your cursor
in that event handler within the Code Editor.
Various attributes of the Object Inspector, such as color and look and feel, are configurable.
Simply right-click over the Object Inspector to invoke the local menu and select the Properties
menu. This will launch the Object Inspector Properties dialog box shown in Figure 3.4.
Introduction to the Integrated Development Environment (IDE) 29
FIGURE 3.4 Object Inspector Properties dialog box.
Code Editor
If you have the opportunity to ever attend a Borland demonstration of one of its products,
you’ll always hear the claim about being able do great things with the products “without
writing a single line of code.” Well, the truth is, you really can’t do anything useful
without writing many lines of code. Fortunately, Borland delivers world class Code Editors
with its development tools. The Delphi for .NET Code Editor does not fall short of this
trend. Here are some handy features of the Code Editor:
• Code Folding—Hands down, this is one of the coolest features of the IDE. Within
the Code Editor, you’ll notice minus (
) and plus (
) signs to the right of code
blocks. By clicking a minus sign, you’ll collapse the block of code. By clicking a plus
04 0672324431 CH03 4/19/04 2:22 PM Page 29
sign, you’ll expand the block of code. Figure 3.5 shows both a collapsed and
expanded block of code. Code folding is enabled automatically for functions, nested
functions, structured types, and unit blocks.
The IDE provides some keyboard shortcuts for people tired of using the mouse (using the default
keyboard mapping). These are
• Ctrl+Shift+K+U—Expands nearest block.
• Ctrl+Shift+K+E—Collapses nearest block.
• Ctrl+Shift+K+A—Expands all blocks in this file.
• Ctrl+Shift K+T—Toggles nearest block.
• Ctrl+Shift+K+O—Turns off/on code folding. (After turning it on, you must change to
another file and back to see it.)
CHAPTER 3 Introduction to Delphi for .NET and the New IDE30
Windows Form Designer generated code
procedure TWinForm.Dispose(Disposing: Boolean);
inherited Dispose (Disposing);
if Disposing then
if Components <> nil then
FIGURE 3.5 Code folding.
• Regions—You can use the
directives to specify your own code
folding blocks. The syntax for using these directives is
{$REGION ‘Region Title’}
Figure 3.6 shows how this looks in the IDE.
• Class Completion—This is a great productivity tool that allows you to define a class,
and then through a shortcut key, the Code Editor will automatically create implemen-
tation methods for you. For instance, suppose that you define the class shown here:
TMyClass = class (System.Object)
procedure Foo;
property MyInt: Integer;
property MyString: String;
04 0672324431 CH03 4/19/04 2:22 PM Page 30
FIGURE 3.6 Regions.
After pressing the Shift+Ctrl+C key combination, the Code Editor creates the follow-
ing class declaration:
TMyClass = class (System.Object)
procedure Foo;
FMyString: &String;
FMyInt: Integer;
procedure set_MyInt(const Value: Integer);
procedure set_MyString(const Value: &String);
property MyInt: Integer read FMyInt write set_MyInt;
property MyString: String read FMyString write set_MyString;
You’ll notice that the property accessor methods have been defined. The implemen-
tation of these methods is also created in the implementation section of the unit as
shown here:
procedure TMyClass.Foo;
procedure TMyClass.set_MyInt(const Value: Integer);
FMyInt := Value;
procedure TMyClass.set_MyString(const Value: &String);
FMyString := Value;
• Code Block Indentation—Another IDE favorite is code block indent/un-indent.
Simply highlight a block of code and use the Ctrl+K+I key combination to indent the
Introduction to the Integrated Development Environment (IDE) 31
procedure TWinForm.Dispose(Disposing: Boolean);
_ end;
inherited Dispose (Disposing);
if Disposing then
if Components <> nil then
{ $ REGION 'Demo'}
04 0672324431 CH03 4/19/04 2:22 PM Page 31
selected block of code. Use Ctrl+K+U to un-indent a block of code. Alternatively, you
can use Ctrl+Shift+I and Ctrl+Shift+U.
• Code Browsing—If you want to find the declaration of a particular function in code,
simply hold down the Ctrl key while left-clicking with the mouse over the function
call. Alternatively, you can use the Alt+Up Arrow key combination to accomplish the
same. To quickly navigate from the definition of a function to its implementation,
use the Shift+Ctrl+Up Arrow/Shift+Ctrl+Down Arrow combination. Also, the IDE
maintains a history of browsed code links. Using Alt+Left and Alt+Right, you can
move back and forth in the browsing history.
Project Manager
From the Project Manager, you manage the various files that are contained within your
Project Groups. It contains three tabs—Project Manager, Model View, and Data Explorer.
Figure 3.7 shows the Project Manager undocked.
CHAPTER 3 Introduction to Delphi for .NET and the New IDE32
FIGURE 3.7 Project Manager (undocked).
A Project Group is a group of related projects. For instance, you have a project group
composed of a project with multiple separate assembly projects. Figure 3.7 shows a Project
. It contains the projects
, and
The Project Manager tab allows you to manage projects groups by providing menu options
to add/remove projects and to compile/build projects contained in the group.
The Project Manager tab also allows you to manage projects by providing menus to
add/remove files as well as compilation options.
04 0672324431 CH03 4/19/04 2:22 PM Page 32
Model View
The Model View gives you a nested view of the projects units, classes, and other members
contained within your projects. Figure 3.8 shows the Model View. Note that the Model
Views is accessed within the Project Manager window by selecting its tab on the lower
portion of the Project Manager Window.
Introduction to the Integrated Development Environment (IDE) 33
FIGURE 3.8 Model View window.
Data Explorer
The Data Explorer (see Figure 3.9) is also accessible from within the Project Manager window.
FIGURE 3.9 The Data Explorer displays connections.
04 0672324431 CH03 4/19/04 2:22 PM Page 33
From the Data Explorer, you can manage various connections to data sources through
Database Providers. You can perform various functions such as creating new connections,
creating projects from connections, browsing databases, and more. The online Delphi for
.NET help provides examples of performing such functions. Developing database applica-
tions is covered in greater detail in Part IV, “Database Development with ADO.NET.”
Object Repository
The Object Repository is the location from which you can use reusable items within your
applications. From the Object Repository, you can select a type of application or elements
that you will use within your application, such as Windows Forms, ASP.NET Forms, classes,
and so on. To open the Object Repository, simply select File, New, Other, which launches
the form shown in Figure 3.10.
CHAPTER 3 Introduction to Delphi for .NET and the New IDE34
FIGURE 3.10 Object Repository is used to select reusable items.
This list on the left represents the various categories of items that you can select from. The
view on the right displays the items for a selected category. For instance, by selecting the
category Delphi for .NET Projects, you will see a list of the various projects you can create
in Delphi for .NET, such as Window Forms Application, VCL Forms Application, Package,
Library, and so on. When you select an item that creates a new application, the IDE will
create the application and application files for you. If you select an element such as a
form, the IDE will create that item for you and will add it to your existing application on
which you are currently working.
Code Explorer
The Code Explorer can be useful for navigating through large units of source code. The
Code Explorer displays the structural layout of a unit including classes, methods, compo-
nents, and so on. To navigate to a particular item, simply double-click it, and it will posi-
tion the cursor on the code in which the item appears. The Code Explorer is shown in
Figure 3.11.
04 0672324431 CH03 4/19/04 2:22 PM Page 34
FIGURE 3.11 Use the Code Explorer to navigate through a unit.
To-Do List
The To-Do list is a convenient way to keep track of to-dos. They are listed in a dockable
window and are maintained in your source files.
To use To-Dos, simply right-click anywhere in the Code Editor and select Add To-Do Item
from the local menu. Doing so will invoke the Add To-Do Item dialog box.
When you press OK after adding the To-Do, the To-Do will be added to the To-Do list that
appears at the bottom of the IDE (see Figure 3.12). If the To-Do list is not displayed, select
View, To Do List from the main menu.
Introduction to the Integrated Development Environment (IDE) 35
04 0672324431 CH03 4/19/04 2:22 PM Page 35
CHAPTER 3 Introduction to Delphi for .NET and the New IDE36
FIGURE 3.12 To-Do list is displayed at the bottom of the IDE.
04 0672324431 CH03 4/19/04 2:22 PM Page 36