views:

228

answers:

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?

+3  A: 

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.

Aikislave
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. ;)
PetriW
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?
Vegar
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.
mj2008
Older versions of Delphi always put them at the end. If you have code that was created in them, then the order will be random
Gerry
A: 

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.

Tiago Moraes
A: 

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.

Mike Sutton
+4  A: 

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&gt+<DnAr> which will quickly jump from method impl to method impl in file-order.

Allen Bauer