_________________________________________________________________________________________________________
Class types
___________________________________________________________________
As many private, protected, published and public blocks as needed can be repeated. Methods are normal function or procedure declarations. As can be seen, 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 (see further in this chapter). The visibility of the different sections is as follows:
It is also possible to define class reference types:
_________________________________________________________________________________________________________
Class reference type
___________________________________________________________________
Class reference types are used to create instances of a certain class, which is not yet known at compile time, but which is specified at run time. Essentially, a variable of a class reference type contains a pointer to the VMT of the speficied class. This can be used to construct an instance of the class corresponding to the VMT. The following example shows how it works:
Type
TComponentClass = Class of TComponent; Function CreateComponent(AClass : TComponentClass; AOwner : TComponent) : TComponent; begin // ... Result:=AClass.Create(AOwner); // ... end; |
More about instantiating a class can be found in the next section.