Basic Delphi - A Text Editor

The Menu Designer

Start a new project by selecting File-> New-> Application from Delphi. Depending on the size of your screen, you may want to resize the Form a little.

Main Menu All good applications have a Menu Bar so we'll add one to our project.

Select the Main Menu from the Component Palette and click on the Form to add the component.

Make sure the component is highlighted on the Form (it will be surrounded by resizing dots) and, in the Object Inspector, change the MainMenu1 Name to MainMenu.

This component is actually the Menu Designer. It is not visible at run time so there are no size or position properties for it.

The size and position of the actual Menu Bar itself is, of course, fixed under the Form's Title Bar.

File Menu Double-click on the MainMenu component on the Form and the Menu Designer will open.

In the Object Inspector, type &File for the Caption and change the Name to mnuFile.

Note the prefix, mnu, - it doesn't really matter but, in some applications, it can be useful to remind yourself what 'sort' of component a particular name refers to. You can invent your own prefixes but I use mnu for Menus, btn for Buttons, and so on.

You'll now find that our little application sports a Menu Bar!

Menu Bar

File Menu1 Back in the Menu Designer, click on the white box below the File item to highlight it.

In the Object Inspector, add the Caption &Open and the Name mnuOpen.

Continue this way to add the Save, the separator and the Exit items. The separator is created by using a simple '-' (minus key) as the caption. You can leave the name as N1.

We can return to the Main Menu and the Menu Designer later, to add more items if we wish, but for now, close the Menu Designer by clicking the Close button on its Title Bar.

Saving Our Project

We probably should save our project now so, from the Delphi Main Menu, select Save As...

We can create a new folder and save unit1.pas. Then select Save Project As... and save the project as TextEditor.dpr - The .pas file is the code from the Code Window (pas standing for the pascal language) and .dpr is a Delphi PRoject file.

If you look in the folder after saving those files, you'll find a few others as well. We'll look at those later.

To re-open our project, simply select Reopen from Delphi's File Menu and click on TextEditor.dpr


In the next part of our project we will add the main text window in order to display the text we want to edit and add some code to make the Open, Save and Exit menu items do something!

Previous | Next