class methods

Top  Previous  Next

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

A Delphi class method can be called through a class reference or an object reference:.

 

type

 TBase = class(TObject)

 public

    class function ClassMethod(xi: Integer): Integer;

 end;

 

...

 

var

  pBase: TBase;

  i : Integer;

begin

  i := TBase.ClassMethod(0);  // calling through a class reference

  pBase := TBase.Create;

  i := pBase.ClassMethod(0);  // calling through a object reference

 

 

The most natural way to translate such class methods is to convert them into C# static methods

 

 

class TBase: public TObject 

{

  public static int ClassMethod( int xi )

  {

    ...

  }

};

 

However static methods cannot be called by an instance in C#. Therefor the call by a class instance is converted to a call of the class itself too:

 

TBase* pBase = NULL;

int i = 0;

TBase::ClassMethod( 0 );  // calling through a class reference

pBase = new TBase;

TBase::ClassMethod( 0 );  // calling through a object reference

 

 

Two problems aren't solved yet in Delphi2C#.

 

1.In the defining declaration of a class method, the identifier Self represents the class where the method is called. In C# however inside of a static function there is no counterpart to Delphi's Self (this isn't defined her).
2.Delphi class methods can be virtual, C# static methods cannot.:

 

 

 

 



This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content