Creating and running a new application
Before we make new programs (they are called apps as they are the most common programs running under Windows), we will learn the basic step that will help, especially the beginners, avoiding unnecessary mistakes.
- After running the Lazarus development environment, we select the Project in the Main menu -> New project and we choose the option Application or we can create a new project by selecting from the main menu as follows: File -> New Project -> Application (Figure 4).
- Subsequently save the running empty application. It is possible to save the project even during its writing, but some beginners may do a lot of mistakes while doing so.
- We choose either in the main menu a quick choice Save or (recommended) we choose once again in the menu Project Save project as. Each new project has to be saved in a new directory! Each project consists of at least 7 files that should be together in one folder and should not overlap with other projects.
- When saving a project, Lazarus will ask to store two files: project1.lpi - a project file that is created automatically and contains important information about the overall structure of our project; unit1.pas - a separate program with a Form. It is important that these files are stored in the folder we have selected!
We have created and saved a new project. Although it is still empty, we can still run it. It will not do anything but we will make sure it works. The program can be run in several ways:
- press F9 button
- press green arrow button in a quick choice menu
- press Run -> Run in the main menu
If there are no errors in the program, it compiles (translates the source code) and runs. If there is a bug in the program, the Message window will show up and report a bug that is necessary to fix and then restart the program. An empty grey window titled Form1 appears after the application starts - this is our running program. The running program behaves like a window in Windows, it can be dragged, enlarged, hidden and so on. The application cannot be restarted while the application is running (the green arrow is now grey). Before we change anything in the Form or program, we close the running program! The program may be closed in several ways:
- press shortcut key ALT+F4
- press red square button STOP in the main menu
- press cross button in the top right
After we stop our first running program, we can now really start programming.