In terms of language feature, class helpers have been around since Delphi 2005, followed by record helpers. These two constructs let you add to an existing class or record new methods, optionally also replacing existing ones. While this is more of a hack than a regular feature, it becomes important when you want to augment the features of an existing class you don't own, for example a library class. There is a caveat, though: you can have only one class helper active for each class at any time. The last visible class helper from the class scope wins over previous ones.

Fast forward to Delphi XE3. We can now write a helper for native types, and this is likely an effect of Embarcadero embracing a new compiler architecture for mobile support and preparing “future” compatibility. It might also be that Delphi is getting inspired by other languages (mostly dynamic ones, though) that provide this feature.

In any case, you can now write:

  TIntHelper = record helper for Integer
    function ToString: string;

and, given an Integer variable n, call:


How do you define that pseudo-method and how can it refer to the variable's value? By stretching the meaning of the self keyword to refer to the value the function is applied to:

function TByteHelper.ToString: string;
  Result := IntToStr (self);

Notice that you can apply methods also to constants, like in:

  Caption := 400000.ToString;

However, you cannot do the same for a small value, as the compiler interprets constants of the smaller possible type. So if you want to get out the value 4 as a string you have to use the second form:

  Caption := 4.ToString; // nope!
  Caption := Integer(4).ToString; // ok

Or you can make the first statement to compile by defining a different helper:

  TByteHelper = record helper for Byte...

The Delphi XE3 RTL takes advantage of this feature offering a rather complete TStringHelper, with dozens of ready-to-use functions. So that the following code will compile (if you add also the Integer helper above):

  s1: string;
  // with a variable
  s1 := 'Hello';
  if s1.Contains('ll') then
    ShowMessage (s1.Substring(3));

  // with a constant
  Left := 'Hello'.Length;

  // chaining
  Caption := ClassName.Length.ToString;
The most relevant application of this new feature in the Delphi XE3 RTL is the TStringHelper I mentioned and used above. You can find some more details at (notice, however, that some of record helpers mentioned like the TGUID record helper were already in XE2). I think Nick Hodges also mentioned this and the fact he like the methods chaining. I fully second it, makes code more readable to me, although I know this is debetable and debated. 
Another interesting idea is the open source TDateTime helper offered by Colin on If everyone builds his own and given you can have only one helper for each type, we might get into some real fragmentation. So having a few open and community shared helpers is a great idea.