[fpc-pascal] Check In Interface Type Helpers

Anthony Walter sysrpl at gmail.com
Wed Aug 23 16:00:37 CEST 2017


Marco, it doesn't work that way.

Type helpers simply allow you to extend an existing type with new methods
and/or properties. When you declare a type helper you extend all instances
of said type given that:

A) You 'use' the unit declaring the type helper in some other unit.
B) No other unit you're using also defines a type helper for that same
type. Only one type helper per type allowed.

As to what they are useful for, consider the following:

type
  // IShellLink is define by Microsoft
  IShellLinkHelper = record helper for IShellLink
  public
    procedure Save(const Target, Description, Link: string);
  end;

procedure IShellLinkHelper.Save(const Target, Description, Link: string);
var
  P: IPersistsFile;
begin
  SetPath(Target);
  SetDescription(Description);
  if Self is IPersistsFile then
  begin
    P := Self as IPersistsFile;
    P.Save(Link, True);
  end;
end;

...

CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER, IShellLink,
Link);

Link.Save('C:\Program Files\Google\chrome.exe', 'Web Browser',
C:\Users\me\Desktop\The Internet.lnk')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170823/f264224a/attachment.html>


More information about the fpc-pascal mailing list