Creating a new project in Delphi
In this topic will be considered:
- the steps of creating and running for execution of Windows-based applications in the Delphi 2010;
- Basic types of files created the Delphi 2010 for developing Windows-based applications.
Contents
Instructions
Creating a new Windows-based applications in Delphi-2010 is carried out in a standard way. The following describes the steps to create Windows-based applications.
1. Run Delphi 2010
In time of running the following window will shown (fig 1).
Fig. 1. The process of run Delphi 2010
After loading, the system will have view as shown on fig. 2.
Fig. 2. The window of Delphi 2010
2. Create a Windows-application
To create Windows-application we should call the next sequence of command in main menu (fig. 3):
File -> New -> "VCL Forms Application - Delphi"
Fig. 3. The command of creating Windows-application in Delphi
This will create the main application form (Fig. 4) that is available in Design mode.
Fig. 4. The main form of application
By default, the main form of application is called Form1. To it, you can use different ways to change her appearance, behavior, etc. with the help of the Object Inspector.
3. Save the project
First of all, when we create a new program (application), we need to save it properly.
It is recommended save a separate project in a separate pre-existing directory. To save the project need to call a command (fig 5.):
File -> Save All
Fig. 5. Saving the project
Saving a project in Delphi occurs in two stages.
First the “Save As” standard window is output, in which you need to specify the location and file name of the main form of the program. The created file has the extension “* .pas“. By default, the system offers file (module) Unit1.pas (see fig. 6).
Fig. 6. The Window “Save Unit1 As”
The next step is offer of whole project saving. The project is saving in file with the “*.dpr” extension.
The window of project saving is shown at figure 7.
Fig. 7. Window “Save Project1 As”
4. The work files of application
After saving of our project, Delphi system creates several files. We describe the main files that are used in the developing of applications.
4.1. Project file
It has “*.dpr” extension. The execution module of application will have the same name as project file.
For example, if the project file was called
myprog1.dpr
then execution module will have “myprog1.exe” name.
If we consider the source code of project file, then we’ll see that it has the Pascal-program structure. In this case, the code of project file is the following:
program myprog1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
In the operators brackets (begin … end.) there are four calls: carrying out initial application initialization, establishing and creating the main form of the application and starting the application.
4.2. The file of main form of application
Created file of main form of application has “*.pas” extension, in which is located directly executable program code written by the programmer. Here You can enter the internal and external variables, your own procedures, event-handling code of the controls placed on the main form, and more. The form file is realized as a separately module. In parallel with the file of form, Delphi (of any version) creates a file with the extension “*.dfm“, which provides information describing the shape (width and height in pixels, the name of the title, etc.).
For example, if in initial saving we specified the following name
main.pas,
then the following file will be created automatically
main.dfm
Listing of file *.dfm, that describes the form is the following:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 206
ClientWidth = 455
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
end
As we see, the newly created form is called as “Form1” (the “Caption” property). It has size by height 206 pixels (ClientHeight), size by width 455 pixels (ClientWidth) and so on.
Every newly created form in application also will have two files with extensions “*.pas” and “*.dfm“.
5. Run the application
Running of application is carrying out by F9 command or by sequential calling
Run->Run
After running can be seen that our application is not yet performs any useful work and not includes any controls (components). However, the application can respond at system menu commands
However, the application is able to respond to the command system menu (minimize, maximize, close), the key combination Alt+F4 (shutdown) and call the system menu with the key combination Alt+gap.
Related topics
- “Windows Forms” type application development in MS Visual Studio 2010 – C#.
- Creating a Windows application in C++ Builder.
- Creating a simple dialog application Windows of type Dialog Based Application.