delphiideclass-completion

In what order does Class Completion put its results?


Example: I create a new unit, declare a class with several methods like constructor, destructor, method1, method2, method3 in that order and then hit Ctrl-Shift-C. The IDE creates all the method bodies automatically, but the order is mixed up and not as it was declared in the interface section.

Now, this is not a problem, but is there a reason for it. It seems to be more difficult to mix that up than to just do it in the order of the declaration.

Or is there some rule to it that makes sense which I cannot see?


Solution

  • This is a bit complicated to answer since it is dependent on how your methods are already arranged.

    If they're already implemented in alphabetical order, it will try and maintain that. If the IDE cannot infer any kind of order, it resorts to dropping them at the end of the file.

    There is another wrinkle where, by convention, if you include a comment in the form: { <ClassName> } before the first block of implemented method and then use that comment to delineate all subsequent class implementations, it will attempt to keep the methods grouped together.

    The alphabetical ordering follows the same rules above, except it may inject the new methods into that logical block delineated by the indicated comment.

    If you use class-completion with a brand new class, you'll notice that the IDE will automatically generate that delineating comment.

    If you let class completion auto-arrange the methods and only use the Ctrl+Shift+UpAr key to navigate between a method's implementation and the declaration, the ordering should be less important.

    Typically, I'll jump to the class decl using the above key-sequence, then use the arrow keys to go to the method in the decl I want, and then use that key-sequence again to quickly get to it.

    Another nice key-sequence is the Ctrl+Alt+UpAr or Ctrl+Alt+DnAr which will quickly jump from method impl to method impl in file-order.