Delphi: Codecompletion to override basemethods

206 views Asked by At

In a class declaration, you can press Ctrl+Space to get a list of virtual methods in the baseclass that you can override.

This list seems to be very limited, though. Ex.

 TMyBaseClass = class(TInterfacedObject)
 protected
   procedure mymethod; virtual;
 end;

 TMyClass = class(TMyBaseClass)
 protected
   {Ctrl+Space here...}
 end;

In TMyClass, I get methods from TInterfacedObject and TObject, but not from TMyBaseClass. Why is that?

-Vegar

EDIT: Forgot my delphi version... I'm using 2007.

1

There are 1 answers

3
Deltics On

Because sometimes these IDE tools work and sometimes they don't (and afaik this is not a problem that is unique to Delphi/RAD Studio).

For example, if you have other edits outstanding which mean that the IDE cannot adequately parse your source up to the current insertion point, then it is likely that such things will be "broken".

In such cases I personally try a quick Ctrl+F9 to see if there are compilation errors that I perhaps may not be aware of. 9 times out of 10 there are, and fixing those then fixes the code insight behaviour.

Recreating your example verbatim in a new unit, I get "mymethod" in my code completion list as expected, so is it possible that in your actual case that your base class and your derived class are actually separated by other code, perhaps even in separate units, and that that other code contains errors "between" the two declarations at the time at which you are trying to invoke code completion?

As a more general point, ime it's better to treat such things as "nice to haves when they work" but to try to develop habits and practices that don't rely on them. In this case the only substitute is knowledge of the methods to be overridden, which isn't much help I admit.