Using Delphi Objects

As mentioned earlier, classes are entities that can contain both data and code. Objects are created instances of those classes. Delphi classes provide you with all the power of object-oriented programming in offering full support of inheritance, encapsulation, and polymorphism.

Declaration and Instantiation

Of course, before using an object, you must have defined it using the class keyword. As described earlier in this chapter, classes are declared in the type section of a unit or program:

type
  TFooObject = class;

In addition to a class declaration, you usually also will have a variable of that class type, or instance, declared in the var section:

var
  FooObject: TFooObject;

You create an instance of an object in Delphi by ...

Get Delphi for .NET Developer’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.