Essential Delphi IDE 10.3
Essential Delphi IDE 10.3
3 - 1
Essential Delphi
IDE 10.3
Sample content of a coming book introducing the Delphi IDE (and updated for Del-
phi 10.3). The material is based (with permission) on classic editions of Mastering
Delphi.
01: A Form Is A
Window
The Delphi IDE is a very complex application, with many feature accumulated
over 25 years the product has been in existence. So the question where to start
covering it is more than legitimate. In this first chapter of the book I want to pro-
vide a practical introduction, in case you've never build an application with
Delphi. Starting from the next chapter I'll go deeper in coverage going over each
of the IDE areas in more and more detail.
Let's start our exploration of Delphi by looking to the simplest scenario, building
Windows applications using the VCL library. This is the easiest starting point, while
most concept will also apply to mobile and multi-device development.
Windows applications are usually based on windows. So, how are we going to create
our first window? We’ll do it by using a form. As the chapter title suggests, a form
really is a window in disguise. There is no real difference between the two concepts,
at least from a general point of view.
note If you look closely, a form is always a window, but the reverse isn’t always true. Some Delphi com-
ponents are windows, too. A push button is a window. A list box is a window. To avoid confusion,
I’ll use the term form to indicate the main window of an application or a similar window and the
term window in the broader sense. In the mobile world these relationships are a bit more intricate
and platform-specific, but the broad concept still applies.
Believe it or not, you already have a working application. You can run it, using the
Run button on the toolbar or the Run | Run menu command or just pressing F9,
and it will result in a standard Windows program. Of course, this application won’t
be very useful, since it has a single empty window with no capabilities, but the
default behavior of any Windows window.
Adding a Title
Before we run the application, let’s make a quick change. The title of the form is
Form1. For a user, the title of the main window stands for the name of the applica-
tion. Let’s change Form1 to something more meaningful. When you first open
Delphi, the Object Inspector window should appear on the left side of the form (if it
doesn’t, open it by choosing View | Tools Windows | Object Inspector or pressing
the F11 key):
The Object Inspector shows the properties of the selected component. The window
contains a tab control with two pages. The first page is labeled Properties. The other
page is labeled Events and shows a list of events that can take place in the form or in
the selected component.
The properties are listed in alphabetical order, so it’s quite easy to find the ones you
want to change, but you can also type the name of the property in the search box to
get quickly to it:
note It is also possible to group properties in the Object Inspector by category, but this feature is sel-
dom used by Delphi developers.
We can change the title of the form simply by changing the Caption property. While
you type a new caption, you can see the title of the form change. If you type Hello,
the title of the form changes immediately. As an alternative, you can modify the
internal name of the form by changing its Name property. If you have not entered a
new caption, the new value of the Name property will be used for the Caption prop-
erty, too.
tip Only a few of the properties of a component change while you type the new value. Most are
applied when you finish the editing operation and press the Enter key (or move the input focus to
a new property).
Although we haven’t done much work, we have built a full-blown application, with a
system menu and the default Minimize, Maximize, and Close buttons. You can re-
size the form by dragging its borders, move it by dragging its caption, maximize it to
full-screen size, or minimize it. It works, but again, it’s not very useful. If you look at
the menu in the Windows Taskbar, you’ll see that something isn’t right:
Instead of showing the caption of the form as the icon caption, it shows the name of
the project, something like Project1. We can fix this by giving a name to the
project, which we’ll do by saving it to disk with a new name.
as simply calling it MainForm means you’ll end up with a number of forms (in dif-
ferent projects) that all have the same name.
The name you give to the project file is used by default at run-time as the title of the
application, displayed by Windows in the Taskbar while the program is running. For
this reason, if the name of the project matches the caption of the main form, it will
also correspond to the name on the Taskbar. You can also change the title of the
application by using the Application | Appearance page of the Project Options dialog
box (choose Project | Options):
As an alternative you can write a line of code to change the Title property of the
Application global object, but that's for a later time.
Using Components
Now it’s time to start placing something useful in our Hello form. Forms can be
thought of as component containers. Each form can host a number of components
or controls.
You can choose a component from the Palette toolbox (by default on the right of the
form designer, under the Project manager. If you choose the Button component
from the Standard page of the Palette, for example, you can do any of the following
four simple ways to place a component on a form:
• Click on the component, move the mouse cursor to the form, press the left
mouse button to set the upper-left corner of the button, and drag the mouse
to set the button’s size.
• Select the component as above, and then simply click on the form to place a
button of the default height and width.
note The Positioning toolbar (which was originally mixed with Align toolbar) is a rarely used feature
these days. But I've decided to keep these steps and the example from the original Mastering Del-
phi book anyway.
This toolbox includes buttons to bring control in front of push the behind other con-
trols, and center them in the form. A separate Align toolbar helps aligning controls
one to the other. Using the last two buttons, you can place a component in the cen-
ter of the form.
Although we’ve placed the button in the center, as soon as you run the program, you
can resize the form and the button won’t be in the center anymore. So the button is
only in the center of the form at start up. Later on, we’ll see how to make the button
remain in the center after the form is resized, by adding some code. For now, our
first priority is to change the button’s label.
Changing Properties
Like the form, the button has a Caption property that we can use to change its label
(the text displayed inside it). As a better alternative, we can change the name of the
button. The name is a kind of internal property, used only in the code of the pro-
gram. However, as I mentioned earlier, if you change the name of a button before
changing its caption, the Caption property will have the same text as the Name prop-
erty. Changing the Name property is usually a good choice, and you should generally
do this early in the development cycle, before you write much code.
note It is quite common to define a naming convention for each type of component (usually the full
name or a shorter version, such as “btn” for Button). If you use a different prefix for each type of
component (as in “ButtonHello” or “BtnHello”), the combo box above the Object Inspector will
list the components of the same kind in a group, because they are alphabetically sorted. If you
instead use a suffix, naming the components “HelloButton” or “HelloBtn,” components of the
same kind will be in different positions on the list. In this second case, however, finding a particu-
lar component using the keyboard might be faster. In fact, when the Object Inspector is selected
you can type a letter to jump to the first component whose name starts with that letter.
Besides setting a proper name for a component, you often need to change its
Caption property. There are at least two reasons to have a caption different from the
name. The first is that the name often follows a naming convention (as described in
the note above) that you won’t want to use in a caption. The second reason is that
captions should be descriptive, and therefore they often use two or more words, as
in my Say hello button. If you try to use this text as the Name property, however, Del-
phi will show an error message:
The name is an internal property, and it is used as the name of a variable referring
to the component. Therefore, for the Name property, you must follow the rules for
naming an identifier in the Pascal language:
• An identifier is a sequence of letters, digits, or underscore characters of any
length.
• The first character of an identifier cannot be a number; it must be a letter or
the underscore character.
• No spaces are allowed in an identifier.
• Identifiers are not case-sensitive, but usually each word in an identifier
begins with a capital letter, as in BtnHello. But btnhello, btnHello, and
BTNHello refer to this same identifier.
tip You can use the IsValidIdent system function in your applications to check whether a given
string is a valid identifier.
While in the sections above we've gone over manual steps, there is a faster way to
set key properties of a component like its Name and Caption, and that is the use of
the Quick Edit feature. Select the component in the form designer, right click on it,
and pick the Quick Edit menu item. You'll see near the component a pane that
allows you to quickly edit those two properties and buttons to expand panels for
managing other common features:
Here is a summary of the changes we have made to the properties of the button and
form. At times, I’ll show you the structure of the form of the examples as it appears
once it has been converted in a readable format (I’ll describe how to convert a form
into text later in this chapter). I won’t show you the entire textual description of a
form (which is often quite long), but rather only its key elements. I won’t include the
lines describing the position of the components, their sizes, or some less important
default values. Here is the code:
object Form1: TForm1
Caption = 'Hello'
OnClick = FormClick
object BtnHello: TButton
Caption = 'Say hello'
OnClick = BtnHelloClick
end
end
This description shows some attributes of the components and the events they
respond to. We will see the code for these events in the following sections. If you run
this program now, you will see that the button works properly. In fact, if you click on
it, it will be pushed, and when you release the mouse button, the on-screen button
will be released. The only problem is that when you press the button, you might
expect something to happen; but nothing does, because we haven’t assigned any
action to the mouse-click yet.
Responding to Events
When you press the mouse button on a form or a component, Windows informs
your application of the event by sending it a message. Delphi responds by receiving
an event notification and calling the appropriate event-handler method. As a pro-
grammer, you can provide several of these methods, both for the form itself and for
the components you have placed in it. Delphi defines a number of events for each
kind of component. The list of events for a form is different from the list for a but-
ton, as you can easily see by clicking on these two components while the Events
page is selected in the Object Inspector. Some events are common to both compo-
nents.
There are several techniques you can use to define a handler for the OnClick event
of the button:
• Select the button, either in the form or by using the Object Inspector’s
combo box (called the Object Selector), select the Events page, and double-
click in the white area on the right side of the OnClick event. A new method
name will appear, BtnHelloClick.
• Select the button, select the Events page, and enter the name of a new
method in the white area on the right side of the OnClick event. Then press
the Enter key to accept it.
• Double-click on the button, and Delphi will perform the default action for
this component, which is to add a handler for the OnClick event. Other com-
ponents have completely different default actions.
With any of these approaches, Delphi creates a procedure named BtnHelloClick (or
the name you’ve provided) in the code of the form and opens the source code file in
that position:
Even if you are not sure of the effect of the default action of a component, you can
still double-click on it. If you end up adding a new procedure you don’t need, just
leave it empty. Empty method bodies generated by Delphi will be removed as soon
as you save the file. In other words, if you don’t put any code in them, they simply
go away.
note When you want to remove an event-response method you have written from the source code of a
Delphi application, you could delete all of the references to it. However, a better way is to delete all
of the code from the corresponding procedure, leaving only the declaration and the begin and end
keywords. The text should be the same as what Delphi automatically generated when you first
decided to handle the event. When you save or compile a project, Delphi removes any empty
methods from the source code and from the form description (including the reference to them in
the Events page of the Object Inspector). Conversely, to keep an event-handler that is still empty,
consider adding a comment to it, like //, so that it will not be removed.
Now we can start typing some instructions between the begin and end keywords
that delimit the code of the procedure. Writing code is usually so simple that you
don’t need to be an expert in the language to start working with Delphi. You can find
many tutorials online if you need help or check the bibliography in the appendix of
this book.
Of the code below, you should type only the line in the middle, but I’ve included the
whole source code of the procedure to let you know where you need to add the new
code in the editor:
procedure TForm1.BtnHelloClick(Sender: TObject);
begin
MessageDlg ('Hello, guys', mtInformation, [mbOK], 0);
end;
The code is simple. There is only a call to a function, MessageDlg, to display a small
message dialog box. The function has four parameters. Notice that as you type the
open parenthesis, the Delphi editor will show you the list of parameters in a hint
window, making it simpler to remember them.
If you need more information about the parameters of this function and their mean-
ings, you can click on its name in the edit window and press F1. This brings up the
Help information. Since this is the first code we are writing, here is a summary of
that description (the rest of this book, however, generally does not duplicate the ref-
erence information available in Delphi’s Help system, concentrating instead on
examples that demonstrate the features of the language and environment):
• The first parameter of the MessageDlg function is the string you want to dis-
play: the message.
• The second parameter is the type of message box. You can choose
mtWarning, mtError, mtInformation, or mtConfirmation. For each type of
note Programmers unfamiliar with the Pascal language might be confused by the distinction between a
function and a procedure. In Pascal and Delphi, there are two different keywords to define proce-
dures and functions. The only difference between the two is that functions have a return value,
while procedures are like “void functions” in C/C++ terms.
After you have written the line of code above, you should be able to run the pro-
gram. When you click on the button, you’ll see the message box shown below:
Every time the user clicks on the push button in the form, a message is displayed.
What if the mouse is pressed outside that area? Nothing happens. Of course, we can
add some new code to handle this event. We only need to add an OnClick event to
the form itself. To do this, move to the Events page of the Object Inspector and
select the form. Then double-click at the right side of the OnClick event, and you’ll
end up in the proper position in the edit window. Now add a new call to the
MessageDlg function, as in the following code:
procedure TForm1.FormClick(Sender: TObject);
begin
MessageDlg ('You have clicked outside of the button',
mtWarning, [mbOK], 0);
end;
With this new version of the program, if the user clicks on the button, the hello mes-
sage is displayed, but if the user misses the button, a warning message appears.
Notice that I’ve written the code on two lines, instead of one. The Delphi compiler
completely ignores new lines, white spaces, tab spaces, and similar formatting char-
acters. Unlike other programming languages, program statements are separated by
semicolons (;), not by new lines.
There is one case in which Delphi doesn’t completely ignore line breaks: Strings
cannot extend across multiple lines. In some cases, you can split a very long string
into two different strings, written on two lines, and merge them by writing one after
the other.
note The fact that Delphi produces standalone executable files implies it does not require run-time
compilation of a source code file (like it happens for JavaScript or Python), it doesn't need compi-
lation of intermediate byte-code or IL representation (like C# or Java), and it doesn't even require
an execution environment like the .NET run-time or the Java virtual machine. Delphi executable
is just binary assembly of the given CPU and platform, desktop or mobile.
The key point is that when you ask Delphi to run your application, it compiles it into
an executable file. You can easily run this file from the Windows Explorer or using
the Run command on the Start button. Compiling this program as usual, linking all
the required library code, produces an executable of about a few hundred Kb (much
more with debug information). By using run-time packages, this can shrink the exe-
cutable to about 20 Kb. Simply select the Project | Options menu command, move
to the Packages page, and select the check box Build with run-time packages:
Packages are dynamic link libraries containing Delphi components (the Visual Com-
ponents Library, for example). By using packages you can make an executable file
much smaller. However, the program won’t run unless the proper dynamic link
libraries (such as vclxxx.bpl) are available on the computer where you want to run
the program. The BPL extensions stands for Borland Package Libraries; it is the
extension used by Delphi (and C++Builder) packages, which are technically DLL
files. Using this extension makes it easier to recognize them (and find them on a
hard disk).
note The xxx in vclxxx.bpl stands for the specific version number, such as csl260.bpl for Delphi 10.3.x.
Each major version of Delphi is incompatible with libraries for previous versions, and has a new
set of run-time packages, with a different number.
If you add the size of this dynamic library to that of the small executable file, the
total amount of disk space required by the program built with run-time packages is
much bigger than the space required by the bigger stand-alone executable file. For
this reason the use of packages is not always recommended. The great advantage of
Delphi over competing development tools is that you can easily choose whether to
use the stand-alone executable or the small executable with run-time packages.
In both cases, Delphi executable files are extremely fast to compile, and the speed of
the resulting application is comparable with that of a C or C++ program. Delphi
compiled code runs much faster than the equivalent code in interpreted or semi-
compiled tools (although improvements in JIT – Just-In-Time compilation – tech-
nology has reduce the gap) and very fast to start as there is no initial compilation
time to incur.
Some users cannot believe that Delphi generates real executable code, because
when you run a small program, its main window appears almost immediately, as
happens in some interpreted environments.
In the tradition of Borland’s Turbo Pascal compilers, the Object Pascal compiler
embedded in Delphi works very quickly. For a number of technical reasons, it is
much faster than any C++ compiler. One reason for the higher speed of the Delphi
compiler is that the language definition is simpler. Another is that the Pascal com-
pilers and linkers have less work to do to include libraries or other compiled source
files in a program, because of the structure of units (the compiled DCU file, more on
this later in the chapter).
note To be honest the compilers based on the LLVM architecture (that is, most of the non-Windows
compilers) are not as fast compiling and significantly slower when linking, as they use more stan-
dard techniques of the LLVM architecture and are less optimized.
note If you are new to the language, notice that Pascal and Delphi use the := operator to express an
assignment and the = operator to test for equality. At the beginning, this can be confusing for pro-
grammers coming from other languages. For example in C and C++, the assignment operator is =,
and the equality test is ==. After a while, you’ll get used to it. In the meantime, if you happen to
use = instead of :=, you’ll get an error message from the compiler
BtnHello.Height div 2;
BtnHello.Left := Form1.ClientWidth div 2 -
BtnHello.Width div 2;
end;
To set the Top and Left properties of the button — that is, the position of its upper-
left corner — the program computes the center of the form, dividing the height and
the width of the internal area or client area of the form by 2, and then subtracts half
the height or width of the button. Note also that if you use the Height and Width
properties of the form, instead of the ClientWidth and ClientHeight properties,
you will refer to the center of the whole window, including the caption at the top
border. This final version of the example works quite well as you can see below:
This figure includes two versions of the form, with different sizes. By the way, this
figure is a real snapshot of the screen. Once you have created a Windows applica-
tion, you can run several copies of it at the same time by using the Explorer or using
Run Without Debugging from the Delphi IDE. By contrast, the Delphi environment
can start only one copy of a program in debugging. When you use the Run button to
start a program within Delphi, you execute it in the integrated debugger, and the
IDE cannot debug two programs at the same time.
note You could possibly start two copies of the Delphi IDE and let each debug a different application,
but this is a more advanced use case than I'm planning to cover in this book.
A Two-Way Tool
In the Hello example, we have written three small portions of code, to respond to
three different events. Each portion of code was part of a different procedure (actu-
ally a method). But where does the code we write end up? The source code of a form
is written in a single Pascal language source file, the one we’ve named
HelloForm.pas. This file evolves and grows not only when you code the response of
some events, but also as you add components to the form. The properties of these
components are stored together with the properties of the form in a second file,
named HelloForm.dfm.
Delphi can be defined as a two-way tool, since everything you do in the visual envi-
ronment ends up in some code. Nothing is hidden away and inaccessible. You have
the complete code, and although some of it might be fairly complex, you can edit
everything. Of course, it is easier to use only the visual tools, at least until you are an
expert Delphi programmer.
The term two-way tool also means that you are free to change the code that has been
produced, and then go back to the visual tools. This is true as long as you follow
some simple rules.
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
end.
The file, named Unit1, uses a number of units and defines a new data type (a class)
and a new variable (an object of that class). The class is named TForm1, and it is
derived from TForm. The object is Form1, of the new type TForm1.
Units are the modules into which a Pascal program is divided. When you start a new
project, Delphi generates a program module and a unit that defines the main form.
Each time you add a form to a Delphi program, you add a new unit. Units are then
compiled separately and linked into the main program. By default, unit files have a
.pas extension and program files have a .dpr extension.
If you rename the files as suggested in the example, the code changes slightly, since
the name of the unit must reflect the name of the file. If you name the file
HelloForm.pas, the code begins with
unit HelloForm;
As soon as you start adding new components, the form class declaration in the
source code changes. For example, when you add a button to the form, the portion
of the source code defining the new data type becomes the following:
type
TForm1 = class(TForm)
Button1: TButton;
...
Now if you change the button’s Name property (using the Object Inspector) to
BtnHello, the code changes slightly again:
type
TForm1 = class(TForm)
BtnHello: TButton;
...
Setting properties other than the name has no effect in the source code. The proper-
ties of the form and its components are stored in a separate form description file
(with a .dfm extension).
note FireMonkey multi-device applications use a very similar structure, only the textual definition of
resources is saved in a file with the .fmx extension
Adding new event handlers has the biggest impact on the code. Each time you
define a new handler for an event, a line is added to the data type definition of the
form, an empty method body is added in the implementation part, and some infor-
mation is stored in the form description file, too.
It is worth noting that there is a single file for the whole code of a form, not just
small fragments for each of the event handlers. This is the complete code of the unit
(something I'd generally avoid to list in the book, as it repeats a lot of boilerplate
code):
unit HelloForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls;
type
TForm1 = class(TForm)
BtnHello: TButton;
procedure BtnHelloClick(Sender: TObject);
procedure FormClick(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
System.UITypes;
end.
Of course, the code is only a partial description of the form. The source code deter-
mines how the form and its components react to events. The form description (the
DFM file) stores the values of the properties of the form and of its components. In
general, source code defines the actions of the system, and form files define the ini-
tial state of the system.
note In the early versions of Delphi the DFM file was a binary file. Now this is by default a text file con-
verted to a binary resource during the compilation process. The binary version is what gets into
the executable, because it is a more compact representation and a faster to process one. Whatever
the format, if you load this file in the Delphi code editor, it will be converted into a textual descrip-
tion.
In any case, you can determine if the DFM is text or binary for a new module by opening the IDE
Tools | Options menu and selecting User Interface | Form Designer going over the Module cre-
ation options and using the check box New forms as text.
You can open the textual description of a form simply by selecting the shortcut
menu of the form designer (that is, right-clicking on the surface of the form at
design-time) and selecting the View as Text command. This closes the form, saving
it if necessary, and opens the DFM file in the editor. You can later go back to the form
using the View as Form command of the local menu of the editor window. The alter-
native is to open the DFM file directly in the Delphi editor.
To understand what is stored in the DFM file, you can look at the next listing, which
shows the textual description of the form of the first version of the Hello example.
This is exactly the code you’ll see if you give the View as Text command in the local
menu of the form (again, in the book I'll generally include snippets of DFM files, but
rarely a complete listing):
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Hello'
ClientHeight = 299
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnClick = FormClick
OnResize = FormResize
PixelsPerInch = 96
TextHeight = 13
object BtnHello: TButton
Left = 261
Top = 137
Width = 113
Height = 25
Caption = 'Say Hello'
TabOrder = 0
OnClick = BtnHelloClick
end
end
You can compare this code with what I used before to indicate the key features and
properties of the form and its components. As you can see in this listing, the textual
description of a form contains a number of objects (in this case, two) at different
levels. The Form1 object contains the BtnHello object, as you can immediately see
from the indentation of the text. Each object has a number of properties, and some
methods connected to events (in this case, OnClick).
note Once you’ve opened this file in Delphi, you can edit the textual description of the form, although
this should be done with extreme care. As soon as you save the file, it will be turned back into a
binary file. If you’ve made incorrect changes, this compilation will stop with an error message, and
you’ll need to correct the contents of your DFM file before you can reopen the form in the editor.
For this reason, you shouldn’t try to change the textual description of a form manually until you
have a good knowledge of Delphi programming.
An expert programmer might choose to work on the text of a form for a number of
reasons. For big projects, the textual description of the form is a powerful docu-
menting tool, an important form of backup (in case someone plays with the form,
you can understand what has gone wrong by comparing the two textual versions),
and a good target for a version control tool. For these reasons, Delphi also provides
a DOS command-line tool, CONVERT.EXE, which can translate forms from the com-
piled version to the textual description and vice verse. As we will see in the next
chapter, the conversion is also applied when you cut or copy components from a
form to the Clipboard.
uses
Vcl.Forms,
HelloForm in 'HelloForm.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
You can see this file with the Project | View Source menu command (historically it
was View | Project Source). As an alternative, you can select the project node in the
Project manager and use the View Source option of the local menu.
What’s Next
In this chapter, we created a simple program, added a button to it, and handled
some basic events, such as a click with the mouse or a resize operation. We also saw
how to name files, projects, forms, and components, and how this affects the source
code of the program. We looked at the source code of the simple programs we’ve
built, although some of you might not be fluent enough in Object Pascal to under-
stand the details.
In the next chapter we'll start exploring the Delphi IDE is a more systematic way,
going over the various features it has. After an overview chapter, the following ones
will delve into very specific areas, like the form designer, the editor, and the debug-
ger.
02: Highlights Of
The Delphi IDE
In a visual programming tool such as Delphi, the role of the environment is cer-
tainly important, and the various tools help you get work done faster. After the
introduction in the last chapter, this second part offers a deeper overview of the IDE
and its features. Now in some cases the topics just introduce deeper coverage in fol-
lowing chapters, while in others there isn't much more to say.
This chapter won’t discuss all of the features of Delphi, but it will give you the over-
all picture and help you to explore some of the environment traits that are not
obvious, while suggesting some tips that may help you. You’ll find more information
about specific commands and operations throughout the book.
note The RAD Studio product over time included additional personalities beside Delphi and C++,
including C#. In other cases additional languages (like PHP and HTML) were supported but not
bundles in the IDE – they required installing a separate development environment.
If you own a RAD Studio license and have installed multiple personalities (that is,
both Delphi and C++ compilers for at least some platforms) you can still decide to
run the IDE by activating a single personality by using the -p flag followed by the
name of the personality you want to use, like for example for my installation:
"C:\Program Files (x86)\Embarcadero\Studio\20.0\bin\bds.exe" "-pDelphi"
If you create a shortcut with this parameter, you can easily start the specific person-
ality using it. Actually the RAD Studio installer already provides similar links in the
Embarcadero RAD Studio folder of the Windows Start Menu:
Installation Folders
Original Delphi versions were installed under the Program Files\Borland folder.
With changes in the product ownership, product name, and the need to support
Windows folder permissions, the overall structure has changed considerably.
The main installation folder for 10.3, using the defaults on an English language ver-
sion of Windows, is:
C:\Program Files (x86)\Embarcadero\Studio\20.0
Under this main folder there are many others. The most notable are :
• bin for all Win32 binaries, including the IDE, compilers, run-time packages
and many utilities
• other binXyz folders include binaries in other formats, like Win64, Linux
and macOS
• lib includes compiled library files (mostly in dcu format, but not only)
• source has extensive run-time libraries source code
Other files are installed outside of the Program Files section of the disk, because
they are meant to be created or modified by the user. These additional folders are
under the Users section of the disk and some of them can be under the individual
user or the Public user depending on installation options. On an English language
version of Windows, and using the defaults, the new projects folder, the examples
folder, the catalog repository, the FireDAC database configuration are respectively:
C:\Users\marco\Documents\Embarcadero\Studio\Projects
C:\Users\Public\Documents\Embarcadero\Studio\20.0\Samples
C:\Users\marco\Documents\Embarcadero\Studio\20.0\CatalogRepository
C:\Users\Public\Documents\Embarcadero\Studio\FireDAC
This is where your configuration is kept with you change IDE options, install pack-
ages, and the like. If you know what you are doing, you can tweak some of these
settings in the registry directly.
You can also create a new snapshot of the configuration settings, by starting the IDE
with the -r flag. This can be handy as you can keep different configurations active at
the same time, for example with different IDE setting and also different third party
packages.
You can also create a stripped down version of Delphi (for faster start-up and
reduced memory consumption) whilst keeping the full version ready to use as
needed.
Technically, the Delphi -r command line parameter specifies the base registry key
to use. For example, create a shortcut like this:
"C:\Program Files (x86)\Embarcadero\Studio\20.0\bin\bds.exe" -rSmall
The first time you run it, Delphi creates a brand new set of registry keys, copying the
default settings (not the current ones) into:
HKEY_CURRENT_USER\Software\Embarcadero\Small\20.0
In other words, the name you provide replaces the BDS name in the registry tree.
tip If you want to export the registry keys for the current configuration, or an additional one, and
merge it with another configuration or move it to a different computer, you can leverage the Set-
tings Migration Tool included with Delphi (migrationtool.exe in RAD Studio bin folder).
In addition to the -r parameter and the -p parameter, there are other command line
parameters you can use when starting Delphi IDE, including:
-ns (no splash): disables the display of the splash screen
-np (no page): disables the Welcome page
-b (build): opens and builds the project passed as parameter
This is a configuration you can easily change later, so don't worry about your initial
selection. I'll start right away covering the style configurations and the desktop con-
figurations, and how you can change them.
As the Delphi IDE starts it has many area, but the most notable section to start with
are those at the top:
• The special toolbar commands hosted in the title bar
• The menu bar
• The customizable toolbar
note Both because this is my preference and because very dark images are more complex to print with
good quality, I'm going to stick with using the Light Theme for most images in this book.
The easier way to change the theme is to use the corresponding icon with the moon
in the menu bar:
As you can see in this menu you can immediately pick the light or dark configura-
tion, select a matching set of editor colors with the Editor submenu or use Theme
Options to open the Theme Manager page of IDE Options dialog, where you can
configure the editor and Object Inspector color configuration associated with the
Light and Dark themes.
The other two items in this menu (Save Desktop and Set Desktop) can be used along
with the desktop selection combo box also in the title bar to activate and configure
desktop settings, covered in the next section.
Desktop Settings
Programmers can customize the Delphi IDE in various ways—typically, opening
many windows, arranging them, and docking them to each other. However, you’ll
often need to open one set of windows at design time and a different set at debug
time. Similarly, you might need one layout when working with forms and a com-
pletely different layout when writing components or low-level code using only the
editor. Rearranging the IDE for each of these needs is a tedious task.
For this reason, Delphi lets you save a given arrangement of IDE windows (called a
desktop setting) with a name and restore it easily. For each IDE status you save
multiple desktop settings and pick a default one:
• The Startup Desktop is selected when the Delphi IDE starts and when no
project is active (for example, after you select the File | Close All menu). The
default option for this desktop configuration is called Startup Layout.
• The Default Desktop is selected when a project is active in the IDE and you
are editing or using the form designers. The default option for this desktop
configuration is called Default Layout.
• The Debug Desktop is selected when you start an application and debug it.
The default option for this desktop configuration is called Debug Layout.
You can modify any of these configuration and override these layouts or add new
ones with new names and define the default one for each IDE status.
Desktop settings are saved in files with the DST extension, which are INI files in dis-
guise. These files are saved in a folder with the version number under
C:\Users\<username>\AppData\Roaming\Embarcadero\BDS\.
The saved settings include the information about the main window, the Project
Manager, the Object Inspector, the editor windows (with the status of the Code
Explorer and the Message View), and many others, plus the docking status of the
various windows.
Here are some excerpts from a DST file, which should be easily readable:
[Main Window]
PercentageSizes=1
Create=1
Visible=1
Docked=0
State=0
...
[ProjectManager]
PercentageSizes=1
Create=1
Visible=1
Docked=1
StayOnTop=0
[MessageView]
PercentageSizes=1
Create=1
Visible=0
Docked=1
StayOnTop=0
[ToolForm]
PercentageSizes=1
Create=1
Visible=1
Docked=1
StayOnTop=0
[PropertyInspector]
PercentageSizes=1
Create=1
Visible=1
Docked=1
StayOnTop=0
SplitPos=111
tip If you want to customize the Welcome page, you can modify some of its configuration files avail-
able in the WelcomePage folder under the main RAD Studio installation folder. There you can find
the core HTML and CSS files, along with the images displayed, plus JavaScript code and more.
◦ The Model View shows UML modeling information when the feature is
active for a project – something that was more popular time ago and
now fairly neglected and seldom used
◦ The Data Explorer shows information about the predefined database
connections and let's you explore, query and modify databases
◦ The Multi-Device Preview helps configuring the mobile and desktop
previews for FireMonkey applications
• The Tool Palette (on the right, below) hosts the palette of available compo-
nents when a designer is active, and lists the entries in the New Items dialog
in other cases.
Another window at the bottom of the IDE generally hosts compiler results, search
results, and a refactoring previews, but also breakpoints lists, event view and other
debug panes. This window is displayed when necessary. There are also dozens of
other windows used by the IDE, including a number of debugger views. I'll cover
these various windows and panes when discussing related topics in this and the
coming chapters.
IDE Insight
Both newcomers and expert users can easily get lost in the large number of menu
items, settings, components, and features you can activate in the IDE. At times even
experts get lost because features were moved from a version of Delphi they spent a
lot of time with. That's why it is great to have searching capabilities in several dialog
boxes and an overall search mechanism for the entire IDE, called “IDE Insight”. The
IDE Insight search box is visible in the title bar, between layouts management and
the Help button:
Beside clicking it with the mouse, you activate typing in this box by pressing the F6
key (or by using Ctrl + <period>). As you start typing, a pull down will show a fil-
tered list of just about anything you might want to look for in the IDE:
As you can see above, the results are filtered by category and they can encompass
many different areas of the development environment – some of which depend on
the current selection (editor, form designer, start-up layout):
playing with the Help system will probably help you understand the structure of
these files and learn how to find the information you need.
The Help files provide a lot of information, both for beginner and expert program-
mers, and they are especially valuable as a reference tool. They list all of the
methods and properties for each component, the parameters of each method or
function, and similar details, which are particularly important while you are writing
code.
As an alternative you can refer to the online product documentation, powered by a
Wiki engine, at
http://docwiki.embarcadero.com/RADStudio/en/Main_Page
tip The online version of the documentation on DocWiki gets updated more frequently than the ver-
sion installed in the product.
If you are working on a form and select Print from the File menu, however, the
printer will produce the graphical representation of the form, offering these options:
Finally, there is the Exit menu item, which prompts you for saving any open file or
project ans shuts down the IDE.
tip It is worth noting that it is not fully recommended to keep a very complex software like Delphi
running for many days in a row. Shutting it down from time to time cleaning up all memory and
resources is a good recommendation.
note Undo in the form designer is not enabled because a large number of component properties cause
side effects that cannot really be reverted. Consider the active property of a database query, which
opens a connection, loads meta data, populate field definitions, creates fields and fetches some
records… how do you undo it? Compared to other IDEs where properties only set individual
fields, the fact Delphi frameworks are more rich and offer live data at design time is the reason a
general Undo operation is extremely complex to define. As a partial solution, there is an editor his-
tory that keeps multiple versions of the source code and designer files.
The copy and Paste operations (and the standard Ctrl+X, Ctrl+C, and Ctrl+V key-
board shortcuts) work both with text and with form components, as covered in the
next section.
Besides using cut and paste commands, the Delphi editor allows you to move source
code by selecting and dragging words, expressions, or lines. If you drag text while
pressing the Ctrl key, it will be copied instead of moved.
There are also additional special operations for the code editor, like MultiPaste,
which allows you to add the same modify multiple lines adding the same text before
each of them and after each of them. This is handy for embedding the text of a SQL
statement in a string or adding multiple lines to a list box (like in the case in the
image below, in which the selected text has just numbers), just to mention two
examples.
Caption = 'Button1'
TabOrder = 0
end
note Actually Delphi adds to the clipboard both the textual description of a component and an image of
the form. If the target editor support graphics, as you paste the content you'll get the option to
pick one or the other.
Now, if you change the name of the object, caption, or position, or add a new prop-
erty, these changes can be copied and pasted back to a form. Here are some sample
changes:
object MyButton: TButton
Left = 200
Top = 200
Width = 180
Height = 60
TabOrder = 0
Caption = 'My Button'
Font.Name = 'Arial'
end
Copying the above description and pasting it into the form will create a button in the
specified position with the caption 'My Button' in an Arial font. To make use of this
technique, you need to know how to edit the textual representation of a component,
what properties are valid for that particular component, and how to write the values
for string properties, set properties, and other special properties. When Delphi
interprets the textual description of a component or form, it might also change the
values of other properties related to those you’ve changed, and change the position
of the component so that it doesn’t overlap a previous copy. You can see how Delphi
modifies the properties of the component by copying it back to the editor. For exam-
ple, this is what you get if you paste the text above in the form, and then copy it
again into the editor:
object MyButton: TButton
Left = 200
Top = 200
Width = 180
Height = 60
Caption = 'My Button'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Arial'
Font.Style = []
ParentFont = False
TabOrder = 1
end
As you can see, some lines have been added automatically, to specify other proper-
ties of the font. Of course, if you write something completely wrong, such as this
code:
object Button3: TButton
Left = 100
eight = 60
end
which has a spelling error (a missing ‘H’), and try to paste it into a form, Delphi will
show an error indicating what has gone wrong:
You can also select several components and copy them all at once, either to another
form or to a text editor. This might be useful when you need to work on a series of
similar components. You can copy one to the editor, replicate it a number of times,
make the proper changes, and then paste the whole group into the form again.
number of matches. You can navigate the results with the arrows and modify some
of the search options with he matching check boxes.
A quicker way to search is to use Search | Incremental Search (Ctrl+E) which moves
to the closest match as you type, with no need to press enter to activate the search:
Incremental search has fewer options, and you can always switch back to the regular
search mode if you need more control.
note Originally, the two search modes had a more clear difference, with Find opening a dialog and
Incremental search using the editor toolbar. Since they were both modified to use a pane at the
bottom of the editor, they have become similar in their user interface, but the behavior remains
distinct. In general, Incremental search remains faster to use.
A third and more classic approach is used by the Search | Replace command, which
opens a dialog for entering the text to find, the replacement text and some options:
All of the find commands above work only on the active editor file. For a broad
search you can use the Search | Find in Files command. This allows you to search
for a string in all of the source code files of a project, all the open files, or all the files
in a directory (optionally including its sub-directories), depending on the radio but-
ton you check in the Where group:
The result of the search will be displayed in the message area at the bottom of the
editor window. You can select an entry to open the corresponding file and show the
specific matches, and than jump to the line containing the text by clicking on it:
A common case is using the Find in Files command to search for components,
classes, and type definitions in the VCL source code.
There are a few configuration options for the Find in Files search. You can request
that Delphi shows the results in a different page as you do a new search, so the
results of previous search operations remain available. You can also use a check box
in the Find Text dialog box to group the search results by source code file, as in the
scenario above. Once you have many pages, you can press the Alt+Page Down and
Alt+Page Up key combinations to cycle through the tabs of this window. (The same
commands work for other tabbed views, but not all of them.)
Syntactic Searches
In the Search menu there are also a few options that allow you to search specific ele-
ments of the code, rather than pure text matches as the operations covered above.
Find Class is a bit of a misnomer, as it allows you to search for data types in general
(indicating the unit a class is into). Given this search is based on the active project,
this encompasses only units included in the project (directly or indirectly via a uses
statement). This is an example of the user interface:
Notice that this search work only with full match, that is if you omit the initial T in
the search above you won't get any of those results. This search will open the unit
with the definition of the symbol (something you can also achieve by using
Cltr+Mouse click on the same symbol in the editor.
Find References and Find Local References provide a list of the locations where the
symbol selected in the editor appears within the current project or only within the
current unit, and displays them at the bottom of the editor screen. Here you can use
the local references (above) and all of them (below) for the TForm36 symbol:
• The Goto Address command might seem strange at first. It can be used only
while debugging the application and after you have compiled it, to find the
source code line corresponding to memory address of the compiled code.
This is an information that some error messages and exceptions show in
their display information. (In fact, this Delphi menu item was originally
called Find Error). Often, however, the error is not in one of the lines of your
code, but in a line of library or system code; in this case the Goto Address
command cannot might not be able to locate the offending line. This is the
user interface:
tip You can search for these entries also in the global Help Insight.
The New Edit Window command opens a second edit window (along with the corre-
sponding designer). It is the only way to view two source code files side by side in
Delphi, since the editor uses tabs to show the multiple files you can load. Each edit
windows has its own set of tabs and open files. Notice that you can drag a tab from
one edit window to the other to re-arrange their position (while you cannot open the
same file in both tabs).
The following section has two menu items for working with type libraries, which is a
fairly advanced area of Delphi.
The following four commands on the View menu can be used to activate the Wel-
come page (in case you closed it), the audit and metrics views (a topic I won't be
covering in the book) and the Configuration manager for project groups, a feature
related with project management and covered in Chapter 6.
Finally the last menu item, Broadcast to device, activates the ability to send the con-
tent of a design time form to your mobile device or desktop, using the matching
LivePreview application. If you don't plan using this feature, you should disable it,
given it opens a communication port for the purpose you probably don't need and
don't want to keep active.
Next there is a section with the main commands for compiling and building the cur-
rent project (the different is that Compile – called Build in other system – works
only on the modified units, while Build – also called Build All – repeats the entire
process from scratch). Syntax Check does a quick scan of the code, with the com-
piler parsing it but skipping code generation. Information for gives summary data of
a the last compiled project:
Finally, Audits, Metrics, and Toxicity Metrics offer different types of information
about the code after analyzing it.
The next section has two commands for the entire project group, Compile All
Projects and Build All Projects. I'll provide some more information on how to cus-
tomize their behavior in Chapter 6.
The final section of the Project menu has a number of unrelated commands:
Resources and Images can be used to add additional external images
and other resource files to a project, so that these resources are bunlded
to the executable file:
Project Page Options allows you to pick an HTML file already included
in the project as the page to be displayed when the project opens (a very
rarely used feature, to my knowledge):
In the same initial section of the menu there are also commands to attach the
debugger to a running application and detach it. What you can do it start a program
without debugging (or from Explorer) and later attach the debugger to it. Finally,
the first section has a sub-menu for ActiveX Server operations, which are in fact
COM Server operations, including registration and the like. The Register ActiveX
Server and Unregister ActiveX Server commands basically add or remove the Win-
dows Registry information about the ActiveX control defined by the current project.
Notice that these operations require to run the IDE with elevated permissions.
The following section has commands used during debugging, to execute the pro-
gram step by step, trace into, stop debugging, set breakpoints, inspect the values of
variables and objects, and so on. Some of these debugging commands are also avail-
able directly in the editor local menu and debugging in general is covered in
Chapter 8.
This wizard shares some logic with the Install Component wizard, which is used to
add a unit with an existing component to a package.
The commands of the last section perform quite distinct operations. Install Pack-
ages opens the package configuration options for the current project (a similar
dialog exists for the entire IDE as whole) and allows you to enable or disable regis-
tered packages or add a new existing, compiled package (.bpl) to the project or IDE:
Import Component (which was originally and more appropriately called Install
ActiveX Library) can be used to create a Delphi component encapsulating a type
library, An ActiveX server or COM server, or a .NET assembly respectively, using
the options in the first page of the wizard:
Finally, Import WSDL opens a wizard to create an interface for a SOAP server by
importing the server definition from a local file or online URL.
There is also a stand-alone command in this menu, Create Component Template,
which is used to create a very simple pseudo-component by copying the configura-
tion of an existing component. This is explained in the following sub-section.
Here you enter the name of the template, the page of the Component Palette where
it should appear, and a custom icon. By default, the template name is the name of
the first component you’ve selected followed by the word template. The default tem-
plate icon is the icon of the first component you’ve selected, but you can replace it
with an icon file. The name you give to the component template will be used to
describe it in the Tools palette.
In this case you might want to call it ThelloButton and after installing it you'll find
the following entry among your components:
If you select it, the IDE will place the component template in the current form and
you'll get a component with the given properties and also with the event handler's
code attached to it as in the original version.
tip All the information about component templates is stored in a single hidden file and there is appar-
ently no way to retrieve this information and edit a template. Now if you add it to a project and
modify it, you can install it again as a component template using the same name and overriding
the previous definition.
In general terms, using Component Templates is a nice trick that can save you some
time and effort, but they have been mostly superseded by frames, which extend and
expand on the concept with much more power and flexibility.
The first command, Options, opens the extremely detailed and complex Options
dialog (originally called Environment Options dialog) of the Delphi IDE. The dialog
box has many pages related to generic environment settings, packages and library
settings, many editor options, a page to configure the Tools Palette, one for the
Object Inspector, and one of the new Code Insight technology. Discussing those
options goes beyond the scope of this chapter, and many of them are covered in dif-
ferent sections of this book.
The Template Libraries command allows you to customize the Object Repository
(part of the content of the File | New | Other dialog box) and covered in Chapter 6.
The GetIt Package Manager command open the GetIt Package manager dialog box,
where you can search for additional components, IDE plug-ins, demos, libraries,
styles, and additional Delphi features provided by Embarcadero and third parties.
From there you can install them is a seamless way:
Manage Platforms is available for Delphi installations made via the (default) Online
Installer, and allows you to add platforms (meaning operating systems targets) you
didn't install at start up and additional features and options (like the Help file, the
product demos, unit testing, charting controls, InterBase Developer Edition and
more). The content of this dialog varies from release to release.
Patterns Organizer opens a repository of coding patterns tie with UML modeling
support integrated with Delphi and not very commonly used these days.
Build Tools offers the ability to configure external tools that can be invoked as part
of the build process to perform any possible external action before the project is
compiled, during compilation phases, or after the linker has completed generating
the binary files. This integrations allows you to configure build operations without
the need to use an external build system – but external build systems are in general
more powerful.
Translation Manager allows to configure the now deprecated VCL translation sup-
port (I already mentioned this as part of the Project | Languages menu item).
Moving to the second part of the menu, the Configure Tools command can be used
to add new entries in the final part of the menu, with the ability to invoke any exter-
nal executable and passing it some parameters that might depend on the current
active project. Complex parameter can be built by clicking the Macros button in the
lower part of the Tool Properties dialog box:
note Using the undocked IDE is not recommended and might be formally deprecated in the future.
RAD Studio DocWiki open the online wiki (already displayed in the sec-
tion Asking for Help earlier in this chapter)
Third-Party Help opens additional help files for Third Party tools, if
available
Platform SDK Help sub-menus have links to online documentation for
the Microsoft Windows API and the Apple macOS platform-specific
The following section has a few links to online pages including Delphi product page
and Embarcadero website. This is followed by a menu item opening the exteranl
License Manager application, which helps you install additional product licenses
and check if they are properly configured and updated with your latest Update Sub-
scription renewals. The Welcome Configuration command opens the dialog
displayed at the first execution of the product.
Finally, the Help | About menu items displays the Delphi About box. In this win-
dow, you can see the product release version, information about your license,
installed third party tools and more. You can also type some not-so-hidden key com-
binations to see can see a list of the people involved in building Delphi.
note The Help menu was often populated by third-party Delphi Wizards (before their default location
became the Tools menu).
First, it is made of multiple areas (that is, multiple toolbar sections) and you can
select which ones are active, by using the toolbar local menu and selecting the vari-
ous elements:
Second you can drag the various sections of the toolbar to new positions, by drag-
ging the separator with 5 vertically align dots on the left of each toolbar section.
Third you can fully customize the toolbar by re-arranging the items and adding oth-
ers not initially available. The toolbar customization is done via a specific fairly
complex dialog box. As you open View | Toolbars | Customize of the Customize
menu items of the toolbar local menu, you see a first page with the various sections
and check boxes to activate them:
This is similar to what we can achieve with the local menu of the toolbar shown ear-
lier. If you move to the commands page however, you can now select one on the
many categories of commands (or actions) and drag them to one of the toolbar sec-
tions to add a new item. While that dialog is visible, you also move items from one
area of the toolbar to a different one, or move them off, deleting them. Here I've
added to new buttons (Options and Build Tools) at the right end of the toolbar:
What’s Next
In this chapter, I’ve offered you an overview of the Delphi IDE and a fairly detailed
analysis of its menus and the features they activate. Starting with the next chapter
I'm going to focus on specific activities you use the IDE for, like designing the user
interface of an application with the form designer (Chapter 3) or writing code in the
editor (Chapter 4).
From there I'll continue getting to more advanced features the Delphi IDE includes,
like code templates and projects management.
Given Delphi is a component-based RAD tool, it expected that developers write code
in its editor but also interact a lot with its visual designer. This can be used to work
on different type of “designer surfaces”:
Forms are the most common type of designer surfaces, and the tool is in
fact generally known as Form Designer. Notice that there are significant
differences when working on working on a VCL form in the designer or a
FireMonkey form.
Data Modules are containers of non-visual components, like database
connection objects or other types of configuration and data access com-
ponents
Frames are some sort of panels that can be hosted by forms, offering a
mechanism to replicate a similar design
I have already guided you step by step on how to add a component to the form
designer and set its properties in the Object Inspector in Chapter 1. Rather than cov-
ering the basics, here I'm going over more detailed and non-obvious information
about the various activities related with designing forms.
note In this section I'll generally refer to the VCL form designer. I'm going to highlight which of the fea-
tures are specific to it. Later on I'll cover what's unique in the FireMonkey form designer instead.
If one control covers another completely, you can use the Esc key to select the par-
ent control of the current one. Press Esc one or more times to select the form, or
press and hold Shift while you click the selected component. Doing so will deselect
the current component and select the form by default.
For moving component, just drag them in the designer. While doing so, a hint will
display the Left and Top positions. There are actually different hints for compo-
nents in the form designer:
As you move the pointer over a component, the hint shows you the name
and type of the component. This is an alternative to the Show Compo-
nent Captions environment setting, which I tend to keep always active.
As you resize a control, the hint shows the current size (the Width and
Height properties). Of course, this feature is available only for controls,
not for non-visual components (which are indicated in the Form
Designer by icons).
As already mentioned, when you move a component, the hint indicates
the current position (the Left and Top properties).
There are two alternatives to using the mouse to set the position of a component.
You can either set values for the Left and Top properties, or you can use the arrow
keys while holding down Ctrl. Using arrow keys is particularly useful for fine-tuning
an element’s position (when the Snap To Grid option is active), as is holding down
Alt while using the mouse to move the control. If you press Ctrl+Shift along with an
arrow key, the component will move only at grid intervals. By pressing the arrow
keys while you hold down Shift, you can fine-tune the size of a component. Again,
you can also do this with the mouse and the Alt key.
note What if you need to move a control at design time by dragging it, but its area is covered by a child
control? Just drag the child control and then press the Esc key (while holding down the mouse
button) to switch the dragging operation to the parent control.
Design Guidelines
The design time guidelines available in Delphi offer you a lot of power for aligning
components to the sides, center, or the text baseline. This is a visual aid to properly
aligning controls on a form. You can align controls to one of their sides, here the
top:
Not only you can align the sides of a control with those of another one, but you can
even align the text baseline:
Controls automatically snap to the guidelines when they are close to them (if the
corresponding option is set). They also snap when they are at a given margin to the
border of the container control.
note Working with the Design Guidelines for the borders of the controls is quite obvious. But how does
the designer knows about the text baseline for a control? Of course, it doesn't: You need to pro-
vide a TComponentGuidelines class and register it with the RegisterComponentGuidelines
function. You can find more details in the DesignEditors and VCLEditors units of the ToolsAPI
VCL source code folder.
There is a gtBaseline value in the TDesignerGuideType enumeration, but it is not really refer-
enced in the code, while the class method TControlGuidelines.GetTextBaseline seems to
provide a default implementation. It looks like you can fully customize the behavior, but having a
ready-to-use example would make this easier
Spacing operations are enabled when multiple components are selected and allow to
increase or reduce the spacing horizontally or vertically and to space the selected
controls equally.
Position operations include ability to change the z-order (bring to front or move to
back) and to center the control or controls in the middle of the form, vertically or
horizontally.
This is different from the buttons used to align horizontal and vertical centers of the
selected controls that are part of the Align operations, along with aligning on each of
the four sides, make controls of the same size, and also enable the grid and snap to
grid options.
Same of the same operations are also available via direct commands or dialog boxes
activated via the local menu of the form designer, as described later.
There you can see, in small, the position of the form on the screen, which is useful if
the form uses absolute positioning (in many cases you let the operating system pick
the position or center the form). You can also use the Form Positioner to modify the
Top and Left properties of the form visually, by dragging that small rectangle.
A little known feature is that you can click the Form Positioner to get (temporarily)
a bigger view and use it to position the form more precisely. Finally, if you have a
background active in Windows, this is going to show up in the Form Positioner
background.
Quick Design is part of the Quick Edit operations (along with the Add Control, Add
Component, and Quick edit commands) covered in a later section in this chapter.
The Edit menu has the standard Cut, Copy and Paste operations, while the Control
menu offers the Bring To Front and Send To Back options to change the relative
position of components of the same kind (you can never bring a graphical compo-
nent in front of a component based on a window).
The Position sub-menu has commands to align controls to the grid, align two or
more selected controls, size them, and scale the entire form. The Align and Size
operations offers the following dialog boxes, which has features someone similar to
the corresponding toolbar buttons I covered earlier:
The Flip Children menu options create a horizontally specular view of the selected
controls or all of the controls of the form, this reverse (right to left) position of the
controls in meant for languages written from the right.
The Tab Order command opens the tab position dialog box, which simplifies the
definition of the TabOrder property for a series of components, given you can list
them all and define the flow in the dialog and the editor will apply the changes to
the respective components property:
The Creation Order dialog box is somehow similar to the tab order editor, but it
affects the creation (and initialization) order of the non-visual controls. In most
cases, you can ignore it as even components with cross references have proper
mechanism allowing their creation in any order.
Hide Non-Visual Components is a relatively new option of the designer, used to
remove the icons for components from the form designer. They remain listed in the
Structure View and in the Object Inspector for selection.
note Other IDEs have a “gutter” area with non-visual components, but Delphi designers decided
against it and that decision was maintained over time.
In an inherited form (or a FireMonkey derived view), you can use the command
Revert to Inherited to restore the properties of the selected component to the values
of the parent form.
You can use the Add to Repository command to add a copy of the form you are
working on to a list of forms available for use in other projects (a rarely used fea-
ture).
Finally, you can use the View as Text command to close the form and open its tex-
tual description in the editor (as already explained in Chapter 1). A corresponding
command in the editor local menu (View as Form) will reverse the situation and get
back to the form designer view. As already discussed, in Delphi all the visual opera-
tions you do are saved in a DFM or FMX file (for VCL and FireMonkey), which by
default uses a text format (it used to be a binary format in the early versions of Del-
phi). The last command of the form designer local menu, Text DFM, toggles the
format used for the form file.
note Having designer files stored as text lets you operate more effectively with version-control systems.
When graphical elements are embedded, though, they are saved as binary data within the text file.
The Grid options enable the display of the grid, automatic snapping , and designer
guidelines (for VCL only). The grid makes it easier to place components exactly
where you want them on the form by “snapping” them to fixed positions and sizes.
Without a grid, it is difficult to align two components manually (using the mouse).
The other options include component captions, hints, the form positioner, and how
to handle non-visual components. There is an option to disable the embedded
designer, which requires restarting the IDE and is not really recommended.
Finally the form creation options determine what happens when you add a new sec-
ondary form (or data module) to an existing application and affect the code added
to the main project file.
The Structure View is particularly useful when working with collection properties
and the database tables fields at design time, and you can use it to create new items
rather than opening the specific designer.
You can drag components within the Structure View—for example, moving a com-
ponent from one container to another (in the case above, you can drag the Button2
control over the Panel1 control to make it a child of the panel. Moving instead of
using cut and paste provides the advantage that any connections among compo-
nents are not lost.
Finally, right-clicking any element of the Structure View displays a shortcut menu
similar to the local menu for a component in the form designer – but this is handy
as you can more easily select the specific component even if its surface is covered by
other child controls. You can also delete items from the tree.
The Palette
Since the introduction of the “Galileo IDE” the Tool Palette (or just Palette, as the
IDE refers to it) replaced the Component Palette as a way to select a new component
to be added to a form or another designer surface. Notice that the Palette is context
sensitive and shows either the list of components (when a designer is active) or the
list of the New Items options (when the editor is active). The content of the Palette
can be filtered by typing it its search box – and we have already seen how you can
directly search for component also in the global IDE Insight search box positioned
in the IDE title bar.
As you start typing, the search is smart enough to allow for partial matches (the
results of course depends on the components you have installed):
note The search in the Palette does not support the use of wild-cards (?, *). This works in the global
search, which means the global search is more handy when you know portions of the words in the
component name. Try for example “but*gr” for Button Group, it works in IDE insight, but not in
the Palette search.
Each page of the palette has a number of components; each component has an icon
and a name, which appears as a “fly-by” hint (just move the mouse on the icon and
wait for a second). The hints show the official names of components, which I’ll use
in this book. They are drawn from the names of the classes defining the component,
without the initial T (for example, if the class is TButton, the name is Button).
If you need to place a number of components of the same kind into a form, shift-
click on that component in the palette. Then, every time you click on the form, Del-
phi adds a new component of that kind. To stop this operation, simply click on the
standard selector (the arrow icon) on the left side of the Component palette.
The Palette can be configured in many different ways. Its local menu has several
configurations settings:
As you can see you can create new custom categories and rename the existing ones
(after which you can drag component icons in this categories, re-arranging the
entire organization), you can collapse or expand categories (and enable/disable the
auto collapsing mechanism), lock the content (disabling dragging), and reset to
default). The Properties menu item opens the configuration page part of the Tools |
Options dialog box:
The right column of the Object Inspector allows only the editing operations appro-
priate for the data type of the property. Depending on the property, you will be able
to do the following actions:
insert a string or a number by typing them
choose from a list of options from a drop down list
invoke a specific editor (indicated by an ellipsis button)
At times more than one of these options are available. For some properties, such as
Color, all three will work: you can type a value, select an element from the list, or
invoke a specific Color editor.
tip Double-clicking on the value of the property can toggle the value, open the next in the list, or open
an editor – depending on the property typo and its configuration.
Other properties, such as Font, can be customized either by expanding their sub-
properties (indicated by a plus or minus sign next to the name) or by invoking an
editor. Also when a property refers to another object you can expand it in place, like
a sub-property.
note Another feature of the Object Inspector is the ability to select the component referenced by a
property. To do this, double-click with the left mouse button on the property value while keeping
the Ctrl key pressed.
In other cases, such as with string lists, the special editors are the only way to
change a property. The sub-property mechanism is available with sets and with
classes. When you expand sub-properties, each of them has its own behavior in the
Object Inspector, again depending on its data type.
Over the years, Delphi added many features to the Object Inspector (some of them
have actually been removed or disabled, as they had issues like the rendering of font
names with the font itself). The drop-down list for a property in the Object Inspec-
tor can include graphical elements. Many of the relevant properties use this feature
by default: Color, Cursor and its variations, generally the ImageIndex property of
components connected with an ImageList (such as an action, a menu item, or a tool-
bar button), the Pen and Brush styles, and a few others. For example, here you can
see a portion of the list of cursors (for the Cursor properties):
Another feature that was added and ended up being ignored quite soon (although it
is still in the product) is the ability to group properties by category. To understand
this feature, you first need to make it visible. To display properties by category
instead of by name, right-click in the Object Inspector and choose the proper
Arrange option from the shortcut menu. You can see the effect of this choice here:
Notice that a property can show up in multiple categories, as categories are not
mutually exclusive.
You can use the View sub-menu from the shortcut menu to hide properties of given
categories, regardless of the way they are displayed (that is, even if you prefer the
traditional arrangement by name, you can still hide the properties of some cate-
gories). If any property is hidden, the Object Inspector status bar will indicate how
many.
Here are some other tips related to the Object Inspector:
The instance list at the top of the Object Inspector shows the type of the
object and allows you to choose a component. You might remove this list
to save some space, considering that you can select components in the
Structure View.
You can optionally view read-only properties in the Object Inspector. Of
course, they are grayed out.
Since Delphi 2010, there is a property editor for Boolean values, which
displays a check box you can use to toggle the value (although the drop
down list with True and False is still available).
You can enable various sections of the Object Inspector with the Show
local menu:
Quick Edit features show up in the local menu of the form designer (and also in the
Quick Action panel of the Object Inspector, as you can see in the last image of the
previous section). Many of the Quick Edits options depend on the selected compo-
nent.
Visual controls have a QuickEdit dialog including also the option to edit the caption
or text, with three additional buttons depending on the control features:
The Align button opens an alignment surface (here is the VCL one, the FireMonkey
one is a bit overcomplicated):
You can visually pick the alignment that you need, or use the two buttons on the
bottom for special cases. Similarly, the layout options offers the ability to easily cus-
tomize the margins and paddings of a visual control:
Having all of these related options in a single screen allows for faster configuration,
and having them graphically depicted makes it also much easier to understand what
you are doing.
tip The locker symbol in the layout configuration of the QuickEdit dialog is used to enter the same
element in all 4 related fields, without having to type the same value multiple times. It is more of a
synchronized edit, than a don't change locker.
The third button opens a color selection pane allowing you to pick either a prede-
fined system or web color, or a specific color value (via RGB, HSL, or mouse click
over the color selector):
Just select one to get going with a ready-to-use layout, like a tabbed dialog:
This is a very nice and quick way to get started with a new form.
All other “container controls” like panels and tabs have similar options for adding
new controls as children (rather than in the form). All of these controls also have the
Add Component menu, but in this case this is for non visual components so it acts at
the form (or designer) level:
Controls with a reference to an ImageList and an Image Index, can set both via a
specific Quick Select Images menu item:
Again, there are other similar menu items that can help doing common operations
for other controls, I recommend you keeping an eye for those as they can speed up
your work considerably.
As you create a data module you'll immediately see the differences, both in the
design surface UI and in the properties in the Object Inspector:
Of course, if you try to add a visual control to a data module, you'll get an error mes-
sage. The Tools palette, in any case, filters out the visual controls when a data
module is the active designer, preventing you from adding them in the first place.
Once you have created a data module, you can refer to it and its components even at
design time from a form (or another designer). Simply select the File | Use Unit
command and at this point the data module components will be available like the
local ones. Here is an example of selecting a data set of a data source on a form,
offering the link to a local data set and one on a data module:
Using Frames
Another designer surface is that of a frame. A frame is a collection of controls and
components that you can “replicate” in one of more forms. Whenever you need to
repeat the same layout in multiple locations, using a frame you can avoid duplicat-
ing the code and configuration, but reuse it. The frame defines a template and each
use is not actually a copy, but a reference: changes to the frame itself gets reflected
in each instance. At the same time, you retain the ability to customize and modify
the instances: each property you change gets disconnected from the original version
(and won't change any more if the original changes) and you can restore it to the
original value.
Frames are a fairly advanced topic to cover here, so I've decided to provide only a
short introduction. Given I introduced Component Templates in the last chapter, let
me just highlight the difference between these two appraoches.