Fandom

Delphi Programming

Interface completion

2,919pages on
this wiki
Add New Page
Talk0 Share

A feature of the Delphi IDE that I learned about only recently is interface completion. Let's say you have got an interface declared like this:

type
   IMyInterface = interface
     procedure MethodA;
     procedure MethodB;
     // lots of more methods
     procedure MethodZ;
   end;

Now you want to write a class that implements this interface:

type
  TMyClass = class(TInterfacedObject, IMyInterface)
  private // implementation of IMyInterface
    // here go all methods that implement IMyInterface
  end;

How do you go about declaring all those methods? Up until recently I used copy and paste. This works fine if the interface declaration is in the same unit or at least in a unit to which you have got the source code, even though it is rather inconvenient. There is a much easier way:

type
  TMyClass = class(TInterfacedObject, IMyInterface)
  private // implementation of IMyInterface
    <press ctrl space here>
  end;

Pressing ctrl space at the position marked above will give you a list of all methods the interface IMyInterface declares, written in red. You can now select all these methods with Shift-Down and press return. Voila, instant declaration. Now just press Control + Shift + C and you also have got an empty implementation.

To see this and other cool stuff in action, see Steve's demo

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki