10.2 Restrictions on class helpers

It is not possible to extend a class with any method or property. There are some restrictions on the possibilities:

The following modifies the previous example by overloading the ToString method:

TObjectHelper = class helper for TObject  
  function ToString(const aFormat: String): String; overload;  
end;  
 
function TObjectHelper.ToString(const aFormat: String): String;  
begin  
  Result := Format(aFormat, [ToString]);  
end;  
 
var  
  o: TObject;  
begin  
  Writeln(o.ToString(’The object’’s name is %s’));  
end.