Addition of missing constructors

Top  Previous  Next

What is translated > Types > Records, Classes, Interfaces > Class > Constructors > Addition of missing constructors

 

Unlike in Delphi, constructors of base classes cannot be called directly in C#. Additional constructor have to be defined in the derived class. Delphi2C# inserts missing constructors in C# automatically. So, resuming the previous example, an additional standard constructor is created, which can be used with all classes, which are derived from TObject:

Unlike in Delphi, constructors of base classes cannot be called directly in C#. If there are public constructors in the base classes with different signatures as any constructor of the derived class, these constructors are generated for the derived class too. Especially in Delphi all classes are derived from TObject and inherit its default constructor. Therefore Delphi2C# generates a default constructor for each derived class, even if such a constructor doesn't exist in the original Delphi code.

 

Sometimes a lot of additional code has to be produced for C# classes. For example a class, which is derived from Exception has more than ten constructors. Inside of each constructor the constructor of the base class has to be called in the initialization list

 

 

public class MyException : Exception

{

  public EArgumentException(string Msg) : base(Msg) {}

  public EArgumentException(string Msg, object[] Args) : base(Msg, Args) {}

.

.

.

 

};

 



This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content