When you start a new VCL project, Delphi creates a project file, containing the code for the project: program Project1; uses Vcl.Forms, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} begin Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(TForm1, Form1); Application.Run; end.In the line Application.CreateForm(TForm1, Form1); we see how the object Form1 is created automatically. It's created from the class TForm1, which is defined in unit Unit1.pas. If you add more forms to your project, you'll see additional lines in the project file, like: Application.CreateForm(TForm2, Form2); Application.CreateForm(TForm3, Form2);
Delphi also has written the unit for your main form as follows: unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs; type TForm1 = class(TForm) private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} end. In the implementation section of Unit1, note this line: object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 299 ClientWidth = 635 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 endLater on, if you define event handlers for the form, they will also be listed here. As for now, we don't have any event handlers. Changing the form's propertiesLet's change a few properties (with the Object Inspector): Save your files and test the application. Adding components to the formLet's add components to our main form, for example: a TEdit, a TButton and a TLabel. Write an event-handler for Button1: double click on Button1 and next complete the Delphi generated code: procedure TForm1.Button1Click(Sender: TObject); begin Label1.Caption := Edit1.Text; end;Save your files and test. Let's say we want the edit-box to be empty at the start of the program. Of course, we could empty its property Text in the Object Inspector; also in Design-view the text would disappear, but we want to keep it as to remind us of the name of the TEdit component. So, let's clear Edit1 right after it is created.
procedure TForm1.FormCreate(Sender: TObject); begin Edit1.Text := ''; end; Have a look at the changes in the type declaration in Unit1.pas and at the text-view of Unit1.dfm and you'll realize how much time Delphi saved you by being "RAD" and "OOP" :) |
|
© Copyright 1999-2018
DelphiLand