Self instance

Top  Previous  Next

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

Like the "this" pointer in C++ is an implicit parameter to all member functions, in Delphi the "Self" instance is an implicit parameter to class functions. Other class methods can be called there through this instance and they can be called by hidden use of "Self". "Self" must not appear in the code. For example:



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


    with Create do  <-- new object from a virtual constructor of Self






  result := xi;




Delphi2C# can convert this code adequately only, if the option to create meta classes is enabled. The code then becomes to:



public static int ClassMethod(int xi)


  int result = 0;

  /*# with Create do */


    TBase  with0 = (TBase) SCreate();





  result = xi;

  return result;




"SCreate" is a static method, which returns a new instance of TBase.

This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content