Quick start manual

2-6
Delphi Language Guide
Example programs
begin
{ calls to Application }
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
Application.Run;
end.
Once again, our program is called Greeting. It uses three units: QForms, which is part
of CLX; Unit1, which is associated with the application’s main form (Form1); and
Unit2, which is associated with another form (Form2).
The program makes a series of calls to an object named Application, which is an
instance of the TApplication class defined in the Forms unit. (Every project has an
automatically generated Application object.) Two of these calls invoke a TApplication
method named CreateForm. The first call to CreateForm creates Form1, an instance of
the TForm1 class defined in Unit1. The second call to CreateForm creates Form2, an
instance of the TForm2 class defined in Unit2.
Unit1 looks like this:
unit Unit1;
interface
uses {different units would be used for a Windows-specific program}
SysUtils, Types, Classes, QGraphics, QControls, QForms, QDialogs;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
uses Unit2; { this is where Form2 is defined }
{$R *.xfm} { this directive links Unit1's form file and would be .dfm for a Windows-
specific application }
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.ShowModal;
end;
end.