Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell Delphi where it must place its automatically created event code?

Tags:

delphi

When a developer double-clicks an event of a control in the Object Inspector and there has not been any code for that event Delphi will automatically create that event's procedure declaration and its code. I would like to know how a developer can tell Delphi or in the least indicate to Delphi where in the unit the implementation part of the events should be placed.

When I create a unit I usually insert a predefined set of comments and I have certain areas in the unit where I add certain type of code. At the very end of the unit I have all the automatically created event procedures. Sometimes I get it right that Delphi will continue to place the automatically created event code at the end of the unit but sometimes it keeps on putting it in between my own manually created procedure. I want to tell Delphi where to place it, if possible.

like image 938
Blurry Sterk Avatar asked Feb 09 '23 05:02

Blurry Sterk


1 Answers

Back in the old days, the IDE added new methods at the end of a class. At some point, I cannot remember when, the IDE was changed so that it attempts to insert new methods to maintain an alphabetical order. If your methods are not in alphabetical order, then I for one have no idea how the IDE decides where to put them. I think it still tries to place them in order, but the code that the IDE uses is based on the (false) assumption that the methods are ordered. Frankly it is something of a mess.

In my opinion, the original approach was better. At least it was predictable. In reality, for most serious development, the developer cares about how to order the methods in the implementation. Each developer will have their own way to do this. And even the same developer will choose different approaches in different situations. The approaches used will typically not be based entirely on the name of the method. What the method does is far more important. Furthermore, I doubt that anyone uses the approach that the methods should be ordered in the same order that they were generated.

So, the obvious conclusion here is that the IDE cannot do a perfect job, and there needs to be manual intervention. The developer is going to want to move methods around, and if the IDE could do anything to help it would make it easy for the developer to re-arrange method implementations, perhaps by dragging them around in a tree view representation of the source.

For you, I don't believe that it is possible to persuade the IDE to place all new methods after all existing methods. So you will simply have to get into the habit of moving a newly generated method to your preferred location.

like image 78
David Heffernan Avatar answered Apr 28 '23 12:04

David Heffernan