|Top Previous Next|
What is translated > class-reference type
In Delphi methods of a class can be called without creating an instance of the class at first. That's similar to C++ static methods. But in C++ it is not possible to assign classes as values to variables and then to create instances of the class by calling a virtual constructor function from such a class reference. This is possible in Delphi however, as shown in the following example code:
TBase = class
TBaseClass = class of TBase;
TDerived = class(TBase)
TDerivedClass = class of TDerived;
function make(Base: TBaseClass): TBase;
result := Base.Create; // will create TBase or TDerived in dependence of the passed parameter
The variables TBaseClass and TDerivedClass are called "class references" of TBase or TDerived respectively.
There is no direct counterpart to class references in C#, but if the option to create meta-classes is enabled, Delphi2C# creates a framework to simulate class references. Parallel to the existing classes, a second hierarchy of class references "ClassRef<T>" is created then and additional methods are written into the original classes, which allow to simulate the most important basic class functions as for example the Create-method. For exceptions there is another but similar hierarchy of ExceptionRef<T> classes.
This page belongs to the Delphi2C# Documentation
|Delphi2C# home Content|