[fpc-pascal] Check In Interface Type Helpers

Sven Barth pascaldragon at googlemail.com
Wed Aug 23 20:25:36 CEST 2017


On 23.08.2017 19:57, Marcos Douglas B. Santos wrote:
> On Wed, Aug 23, 2017 at 2:45 PM, Sven Barth via fpc-pascal
> <fpc-pascal at lists.freepascal.org> wrote:
>> Am 23.08.2017 19:39 schrieb "Marcos Douglas B. Santos" <md at delfire.net>:
>>>
>>> Wait a minute. Now I realize that procedure IShellLinkHelper.Save is a
>>> real implementation not by a class, but by a "interface helper".
>>> It's like default methods in Java(?) that we have code inside an
>>> interface...
>>
>> 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)
> 
> Would we have any problem of memory leaks using Interface helper with
> COM interfaces (refcount)?
> I mean, the "type helper" has constructor/destructor to create/release
> something?

It doesn't need to. A type helper is essentially syntactic sugar for a
class method with the extended parameter as first type.

Take this for example:

=== code begin ===

type
  TInterfaceHelper = type helper for IInterface
    procedure Something(aArg: String);
  end;

// is more or less equivalent to

  TInterfaceHelper = class
    class procedure Something(aExtended: IInterface; aArg: String);
  end;

=== code end ===

Sidenote: for primitive types and records the hidden Self parameter of
the helper is a "var" parameter as the extended type can be changed.

Regards,
Sven



More information about the fpc-pascal mailing list