Wikia

Delphi Programming

Interface completion

Talk0
2,910pages on
this wiki

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

Around Wikia's network

Random Wiki