<p>Am 23.08.2017 19:39 schrieb "Marcos Douglas B. Santos" <<a href="mailto:md@delfire.net">md@delfire.net</a>>:<br>
><br>
> On Wed, Aug 23, 2017 at 11:00 AM, Anthony Walter <<a href="mailto:sysrpl@gmail.com">sysrpl@gmail.com</a>> wrote:<br>
> > Marco, it doesn't work that way.<br>
> ><br>
> > Type helpers simply allow you to extend an existing type with new methods<br>
> > and/or properties. When you declare a type helper you extend all instances<br>
> > of said type given that:<br>
> ><br>
> > A) You 'use' the unit declaring the type helper in some other unit.<br>
> > B) No other unit you're using also defines a type helper for that same type.<br>
> > Only one type helper per type allowed.<br>
> ><br>
> > As to what they are useful for, consider the following:<br>
> ><br>
> > type<br>
> >   // IShellLink is define by Microsoft<br>
> >   IShellLinkHelper = record helper for IShellLink<br>
> >   public<br>
> >     procedure Save(const Target, Description, Link: string);<br>
> >   end;<br>
> ><br>
> > procedure IShellLinkHelper.Save(const Target, Description, Link: string);<br>
> > var<br>
> >   P: IPersistsFile;<br>
> > begin<br>
> >   SetPath(Target);<br>
> >   SetDescription(Description);<br>
> >   if Self is IPersistsFile then<br>
> >   begin<br>
> >     P := Self as IPersistsFile;<br>
> >     P.Save(Link, True);<br>
> >   end;<br>
> > end;<br>
><br>
> Wait a minute. Now I realize that procedure IShellLinkHelper.Save is a<br>
> real implementation not by a class, but by a "interface helper".<br>
> It's like default methods in Java(?) that we have code inside an interface...</p>
<p>I don't know about Java, but the C# equivalent would be extension methods. And yes, that's the point: the implementation is not part of the interface implementer, but the user of the interface can add some implementation. (Same for class, record and primitive types helpers)</p>
<p>Regards,<br>
Sven</p>