next up previous contents index
Next: Properties Up: Classes Previous: Classes

Class definitions

The prototype declaration of a class is as follows :

TObj = Class [(ParentClassType)]
  [Constructor ConstructorName;]
  [Destructor DestructorName;]
  Field1 : Type1;
  ...
  Fieldn : Typen;
  Method1;
  Method2;
  [private
  PrField1 : PrType1;
  ...
  PrFieldn : PrTypen;
  PrMethod1;
  ...
  PrMethodn;
  ]
  [protected
  PuField1 : PuType1;
  ..
  Pufield1 : PuTypen;
  PuMethod1;
  ...
  PuMethodn;
  Property1;
  ...
  Propertyn;
  [public
  PuField1 : PuType1;
  ..
  Pufield1 : PuTypen;
  PuMethod1;
  ...
  PuMethodn;
  Property1;
  ...
  Propertyn;]
  [published
  PuField1 : PuType1;
  ..
  Pufield1 : PuTypen;
  PuMethod1;
  ...
  PuMethodn;
  Property1;
  ...
  Propertyn;]
You can repeat as many private and public blocks as you want. Methods are normal function or procedure declarations.

As you can see, the declaration of a class is almost identical to the declaration of an object. The real difference between objects and classes is in the way they are created;

The visibility of the different sections is as follows:

Private
All fields and methods that are in a private block, can only be accessed in the module (i.e. unit) that contains the class definition. They can be accessed from inside the classes' methods or from outside them (e.g. from other classes' methods)
Protected
Is the same as Private, except that the members of a Protected section are also accessible to descendent types, even if they are implemented in other modules.
Public
sections are always accessible.
Published
Is the same as a Public section, but the compiler generates also type information that is needed for automatic streaming of these classes. Fields defined in a published section must be of class type. Array peroperties cannot be in a published section.

Classes must be created using their constructor. Remember that a class is a pointer to an object, so when you declare a variable of some class, the compiler just allocates a pointer, not the entire object. The constructor of a class returns a pointer to an initialized instance of the object.

So, to initialize an instance of some class, you do the following :

  ClassVar:=ClassType.ConstructorName;

Remark :


next up previous contents index
Next: Properties Up: Classes Previous: Classes

Michael Van Canneyt
Thu Sep 10 14:02:43 CEST 1998