- Delphi for .NET—a Bigger Picture
- Introduction to the Integrated Development Environment (IDE)
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.
NOTE
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 usability, you can visit http://www.delphiguru.com, 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.
TIP
If for some reason you lose the Welcome page, you can redisplay it by clicking View, Welcome Page.
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.
TIP
You can modify the default.htm file in the Welcome Page directory to customize your Welcome pageincluding your own linkschange the shown picture, and so on.
Designer
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 TextBox, it is placed exactly where you positioned it on the form (Figure 3.2). Nonvisual components, such as the SqlDataAdapter and SqlConnection, 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.
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 ControlWhen 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 OrderSomething 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 clicking 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.
DockingThe IDE allows you to reposition/doc the various windows almost wherever you want. This great feature enables you to adjust your work space as you like.
-
LayoutsThere are three predefined desktop layouts: Default, Classic (for those of you who prefer the classic Delphi undocked layout), and Debug. The Default layout 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 MenuYou 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.
Figure 3.3 IDE Debug layout.
Forms
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 functionally 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.
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.
NOTE
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 http://www.go-mono.com/.
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.
Object Inspector
Through the Object Inspector (refer to Figure 3.2), you modify the properties of components 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 Text 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 Click 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.
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 FoldingHands 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 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.
-
Ctrl+Shift+K+UExpands nearest block.
-
Ctrl+Shift+K+ECollapses nearest block.
-
Ctrl+Shift+K+AExpands all blocks in this file.
-
Ctrl+Shift K+TToggles nearest block.
-
RegionsYou can use the $REGION/$ENDREGION directives to specify your own code folding blocks. The syntax for using these directives is
TIP
The IDE provides some keyboard shortcuts for people tired of using the mouse (using the default keyboard mapping). These are
TIP
Ctrl+Shift+K+OTurns off/on code folding. (After turning it on, you must change to another file and back to see it.)
Figure 3.5 Code folding.
{$REGION 'Region Title'} code {$ENDREGION}
Figure 3.6 shows how this looks in the IDE.
Class CompletionThis is a great productivity tool that allows you to define a class, and then through a shortcut key, the Code Editor will automatically create implementation methods for you. For instance, suppose that you define the class shown here:
TMyClass = class (System.Object) private procedure Foo; public property MyInt: Integer; property MyString: String; end;
Figure 3.6 Regions.
After pressing the Shift+Ctrl+C key combination, the Code Editor creates the following class declaration:
TMyClass = class (System.Object) private procedure Foo; public FMyString: &String; FMyInt: Integer; procedure set_MyInt(const Value: Integer); procedure set_MyString(const Value: &String); public property MyInt: Integer read FMyInt write set_MyInt; property MyString: String read FMyString write set_MyString; end;
You'll notice that the property accessor methods have been defined. The implementation of these methods is also created in the implementation section of the unit as shown here:
{TMyClass} procedure TMyClass.Foo; begin end; procedure TMyClass.set_MyInt(const Value: Integer); begin FMyInt := Value; end; procedure TMyClass.set_MyString(const Value: &String); begin FMyString := Value; end;
Code Block IndentationAnother 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 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 BrowsingIf 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 tabsProject Manager, Model View, and Data Explorer. Figure 3.7 shows the Project Manager undocked.
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 Group, ProjectGroup1. It contains the projects Project1.exe, Package1.dll, and Console1.exe. 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.
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.
iFigure 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.
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 applications 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.
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, components, and so on. To navigate to a particular item, simply double-click it, and it will position the cursor on the code in which the item appears. The Code Explorer is shown in Figure 3.11.
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.
Figure 3.12 To-Do list is displayed at the bottom of the IDE.