You are on page 1of 2

17

Object Pascal

Introduction
One of the key ways in which Delphi scores over languages such as Visual Basic is
that it is object oriented. The Pascal engine in Delphi is based on the very
successful Object Pascal from Borland.

What are Objects?


An object is a user defined type, like the record structures that we have looked at.
The difference is that an object also has a set of operations or methods that can be
carried out on those types.
You have already used objects throughout this book every time you created or
used a component. Every component is an object, and the set of operations that
you can perform on each component are the methods for that object. This is why
the window that gives details of the properties of components is called the Object
Inspector.
When you create an object, it can be used by other applications to increase
productivity and to reduce errors.

The TForm Object


All objects have a type. For example, when you create a form, the default name for
the first form is form 1 if it is of type TForml, which is based on the type TForm.
The template code for a form in file Unitl.Pas looks like this:

J. Cowell, Essential Delphi 2.0 Fast 171


© Springer-Verlag London Limited 1996
172 Essential Delphi 2.0 Fast

unit unitl;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
type
TForml = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
forml: TForml;

implementation
{$R *.DFM}
end.

This file is called a unit.


The form type is declared in the var section; all other sections are blank until
another component is added.
If, for example, a button is added to the screen, this file becomes:

unit unit1;

interface

uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Frms, Dialogs, StdCtrls;

type
TForml = class(TForm)
Buttonl: TButton;
procedure ButtonIClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

You might also like