Creating a Console Application

This section describes how to create a console application and introduces you to various files created by the IDE.

Creating a New Project

A project is simply a collection of files used to build an application. Delphi has an immense selection of different projects and a lot of ways to create them. In previous versions of Delphi, the only way to create a console application was by using the New Items dialog box. To display the New Items dialog box, select File ® New ® Other. The New Items dialog box displays all project types available in Delphi.

image from book
Figure 1-8: Creating a new project

To create a new console application project, you have to select the Delphi Projects node in the Item Categories tree and then double-click the Console Application icon on the right.


Delphi automatically closes the open project when you create a new one, but if you want to close the open project yourself, the fastest way to do so is to select File ® Close All.

When you create a console application project, all visual design tools will be disabled because console applications do not have a visual user interface. Console applications are Windows applications that are displayed in the console window and look like DOS applications.

image from book
Figure 1-9: A simple console application

A faster way to create a console application project in Delphi 2005 and newer versions is to select the Delphi Projects category in the Tool Palette window and double-click the Console Application item.

Project Files

To review files that make up the console application project, we have to save the project to disk. The fastest way of saving the entire project to disk is to use the File ® Save All option or click the corresponding button on the Standard toolbar (the icon with two overlapped floppy disks).


Always save projects into separate directories. If you save more than one project into a directory, you may inadvertently rewrite a file that belongs to another project and that will render the other project useless.

When you select the File ® Save All option, Delphi asks you to enter the name for your project. To simplify things, accept the name Delphi suggests and click Save after you've created and/or selected an empty folder.

The important files that define a console application have the extensions .dpr, .bdsproj, and .cfg. The most important file in every project is the .dpr file — the Delphi project file. The project file contains the essential portions of code that define the project and make it work. When you create a console application project, Delphi automatically displays the project's source code in the editor, as shown in Figure 1-10 on the following page.

image from book
Figure 1-10: Project source code

Like .dpr files, both .cfg and .bdsproj files are text files, but unlike the .dpr file, they contain project settings rather than code. The .cfg file contains project configuration settings and the .bdsproj file contains various settings like compiler directives, search paths, and a link to the .dpr file. The .bdsproj file is the new XML-based project file that contains project settings that can be viewed and changed in the Project Options dialog box.

image from book
Figure 1-11: Project Options dialog box

Compiling Projects

Compilation is the process of creating an executable file from one or more files containing source code. To compile a project in Delphi, select Project ®Compile or Project ® Build. After you select either option, Delphi compiles the project file into an executable file with the project name and the extension .exe and places the executable file into the project directory.

Currently, it makes no difference whether you use Compile or Build to create the executable file. But there is a difference in larger projects that have more than one unit (source code module). When you use the Compile option, only the units that were changed since the last compilation are recompiled. When you use the Build option, however, all units are recompiled, regardless of their last compilation status.

To test the application, run it from the IDE using the Run ® Run option. When you run the application from the IDE, the application is first compiled and then run. When the application starts, all designer windows except the Code Editor are hidden and are replaced by debug windows. If you want to run the application without bringing up the debug windows, select Run ® Run Without Debugging.

The executable file Delphi created in the compilation process is a fully functional standalone Windows application that can be distributed and run on other machines. The only problem with this application is that it doesn't do much — it actually does nothing. To see how to create an application that does something, turn the page to Chapter 2.

Inside Delphi 2006
Inside Delphi 2006 (Wordware Delphi Developers Library)
ISBN: 1598220039
EAN: 2147483647
Year: 2004
Pages: 212
Authors: Ivan Hladni

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: