Txxx = class helperfor T ... {T ... indicates an existing class}
  {Can replace existing methods}
  {Can also have new methods, members}
end ;

// When you use the T ... class and its descendants later, the modification of Txxx will be used first.


Example 1:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type 
  TForm1 =class (TForm)
    Button1: TButton;
    procedure Button1Click (Sender: TObject);
  end ;

  TMyClass = class
    function func1:string ;
    function func2:string ;
  end ;

  TMyClassHelper = class helperfor TMyClass
    function func1:string ; {The method with the same name of TMyClass will be replaced}
    function func3:string ; {This method will be added to TMyClass and its subclasses}
  end ;

var
  Form1: TForm1;

implementation

{$ R * .dfm}

{TMyClass}

function TMyClass.func1:string ;
begin 
  Result: ='TMyClass.func1';
end ;

function TMyClass.func2:string ;
begin 
  Result: ='TMyClass.func2';
end ;

{TMyClassHelper}

function TMyClassHelper.func1:string ;
begin 
  Result: ='TMyClassHelper.func1';
end ;

function TMyClassHelper.func3:string ;
begin 
  Result: ='TMyClassHelper.func3';
end ;

//test
procedure TForm1.Button1Click (Sender: TObject);
var
  obj: TMyClass;
begin
  obj: = TMyClass.Create;

  ShowMessage (obj.func1); {TMyClassHelper.func1}
  ShowMessage (obj.func2); {TMyClass.func2}
  ShowMessage (obj.func3); {TMyClassHelper.func3}

  obj.Free;
end ;

end .


Example 2: This example adds a method to the TControl class, and then TControl and all its descendants have this method.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type 
  TForm1 =class (TForm)
    Button1: TButton;
    procedure Button1Click (Sender: TObject);
  end ;

  TMyClassHelper = class helperfor TControl
    procedure MyMsg;
  end ;

var
  Form1: TForm1;

implementation

{$ R * .dfm}

{TMyClassHelper}

procedure TMyClassHelper.MyMsg;
begin 
  ShowMessageFmt ('The class name of% s is% s', [Name, ClassName]);
end ;

// Test: The current form and current button are tested here, they are inherited from TControl
procedure TForm1.Button1Click (Sender: TObject);
begin 
  Self.MyMsg; { Class1             's class name is TForm1}
  TButton (Sender) .MyMsg; {Class name of Button1 is TButton1}
end ;

end .