In what order does Class Completion put its results?
Asked Answered
X

4

4

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?

Xanthippe answered 9/2, 2009 at 12:25 Comment(0)
E
12

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.

Equatorial answered 9/2, 2009 at 20:25 Comment(0)
V
3

By default, I'm pretty sure it tries to create them in alphabetical order by method name, and then tries to keep to this when more methods are added afterwards using the same method. The end result can be a bit of a random mix on ordering.

Vitellus answered 9/2, 2009 at 12:34 Comment(4)
Yeah, it creates methods in alphabetical order until you manually screw it up. Then it starts adding at the end, or in the middle if it feels it fits there. ;)Peggi
I would love a setting for this. How much easier wouldn't it be if it just put it in the same order as in the implementation-section?Rondarondeau
FWIW, the ModelMaker Code Explorer can re-order the class and file definitions to your spec. Neat facility, and helps tidy for the automatic insertion.Deguzman
Older versions of Delphi always put them at the end. If you have code that was created in them, then the order will be randomGloom
H
0

From my experience I find that some times the IDE creates the methods in alphabetical order, but other times it just append the new methods to the end of the file.

Handedness answered 9/2, 2009 at 12:34 Comment(0)
S
0

The IDE tries to create everything in alpahabetical order. But, if the methods become out of sequence (eg you rename a method) it gets in a muddle. The exact behaviour seems to depend on the version. Older versions would simply append the new method to the end of the file in any order. Newer versions seem a bit cleverer, but I haven't worked out exactly how yet.

Shanley answered 9/2, 2009 at 16:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.