Form-based Applications

You can quickly add components to forms and produce impressive-looking applications. Rapid Application Development (RAD) depends on much previous work by developers to create visual components (controls) that will be used in a wide variety of applications. For example, the string grid and its ancestors in Lazarus required 11000 lines of source code in Grids.pas. You can use a string grid to display, load, save and edit records and to sort them by a string field. This may be exactly what you need for a prototype to discuss with your end user. However, if you rely on the code of others and write only a few lines of your own you will be unlikely to cope well in unfamiliar situations in the future. We advise you code your own versions of recognised sorting and searching algorithms and to base your database-type applications on arrays and files of records. You should be able to adapt our demonstration code for console programs to your form-based applications.

See our guides to getting started with form-based applications using Lazarus, Delphi 7 and Delphi 2007. They cover examples of the use of buttons, edit boxes, labelled edits and multiple forms. You should read also our tutorial entitled Object-Oriented Pascal, because components are objects with properties and methods. You can set the many of the properties by several methods:
  1. using the Object Inspector;
  2. editing the text view of the form;
  3. writing code such as lblResult.Caption := 'You won!';
  4. (for positions and sizes of visual components) dragging the bounding rectangles in the design view of the form.
The second method is useful for copying properties from other forms, such as from our demonstrations. You need to save the file before your changes take effect. Make sure that the properties in the text view of the form are the same as those in the Object Inspector. You can select the menu option Run > Build All to check the application before executing it. We supply the text view of each form rather than provide a screenshot of the Object Inspector. If you base part of your application on a demonstration you may prefer to look at the values of the key properties in our text view of the form then set them for your component using the Object Inspector.

We usually prefix component names according to the convention given in this online coding standards page.

We concentrate on using the Lazarus IDE so that beginners can make progress without needing to buy Delphi. You will probably find that you can use many components intuitively, so we do not think it is worthwhile for us routinely to "double up" and demonstrate Delphi also. Follow these steps to try the Lazarus examples in Delphi:

  • Omit from the uses section any units such as Interfaces that Delphi does not recognise;
  • Change the compiler directive {$R *.lfm} to {$R *.dfm};
  • Rename the Lazarus form files from *.lfm to *.dfm. You need to delete any lines that Delphi does not recognise, such as LCLVersion = '0.9.30';
  • The new project file will have the extension .dpr instead of .lpr.

Some of the components that we use in demonstrations do not appear in the title of a section. Here is an alphabetic list of 53 components with a link to a section in which we use each one.

TADOTable, TBitBtn, TBufDataset, TButton, TCalendarDialog, TChart, TCheckBox, TColorDialog, TComboBox, TComboBoxEx, TDataSource, TDateTimePicker, TDBCalendar, TDBEdit, TDBDateEdit , TDBGrid,TDBImage, TDBNavigator, TDBText, TEdit, TFontDialog, TGeckoBrowser, TGroupBox, TImage, TImageList, TIpHtmlPanel, TLabel, TLabeledEdit, TListBox,TLvlGraphControl, TMapViewer, TMemDataset, TMemo, TMenu, TMenuItem, TMVGLGeoNames, TODBCConnection, TOpenDialog, TOpenGLControl, TPageControl, TPaintBox, TRadioGroup, TSaveDialog, TScrollBar, TShape, TSQLQuery, TSQLTransaction, TStaticText, TStringGrid, TSynEdit, TTimer, TTrackbar, TTreeView, TWebBrowser

Since we wrote most of this tutorial Jerzy Griffiths contributed his professional-looking Delphi XE4 word processor. He uses a big range of components to good effect.

Follow the links below to the sections of the tutorial.

Programming - a skill for life!

Pascal Programming Tutorials