non virtual class methods

Top  Previous  Next

What is translated > Types > Records, Classes, Interfaces > Class > class methods > non virtual class methods

A non-virtual Delphi class method is translated to a C# static method.

 

type

  TBase = class(TObject)

  public

    class function ClassMethod(X: Integer): Integer;

  end;

 

class function TBase.ClassMethod(X: Integer): Integer;

begin

  Result := X;

end;

 

Generated C#:

 

public class TBase : TObject

{

    public static int ClassMethod(int X)

    {

        int result;

 

        result = X;

 

        return result;

    }

}

 

In Delphi, a class method can be called through the class type:

 

I := TBase.ClassMethod(0);

 

It can also be called through an object reference:

 

PBase := TBase.Create;

I := PBase.ClassMethod(0);

 

In C#, static methods are called through the class name. Therefore both calls are translated to a static C# call:

 

I = TBase.ClassMethod(0);

 

Even if the Delphi source calls the method through an object reference, the generated C# code calls the static method through the declaring class.

 

This is correct for non-virtual class methods, because their dispatch is not polymorphic.



This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content