问题
Class completion in Delphi is a big time-saver, but I haven't found a way to customize it.
I would like a getter and setter for a property to be grouped together instead of being thrown all over my unit; The interface part is generated properly, but the implementation section becomes a mess if you leave things up to the IDE. I want methods to be ordered like this by default:
function TAaa.getAaa();
procedure TAaa.setAaa();
procedure TAaa.Baa();
function TAaa.getCow();
procedure TAaa.setCow();
procedure TBbb.getAaa()
I want the implementation section to be in the same order as the interface;
I want the body of a generated method to look something like this:
.
procedure TMyClass.MyProc;
begin
{ TODO -oWouter -cimplement autogenerated stuff : implement Procedure MyProc() }
raise Exception.create('procedure TMyClass.MyProc() is not yet implemented');
end;
Are there tools around to do this, or is it needed to dive into the opentools API to get something like this done?
Related question: In what order does Class Completion put its results?
回答1:
Question 1: I would like a getter and setter for a property to be grouped together.
The Modelmaker Code Explorer (MMX) has a sorting tool. The tool sorts class members in the interface and the implementation. The 4.05 version, I'm using, does not support your kind of sorting. However, the Modelmaker website contains a page that shows the most up to date sorting functionality and it appears they extended the sort functionality with many new options. Maybe you can group your getter/setter methods with their latest MMX tool. Handy functionality:
- Drag and Drop sorting in the MMX class explorer: you drag the method to the new location and modelmaker moves the code
- Sorting hints: MMX will inform you if a method is not sorted according to your default sorting template
Question 2: I want the implementation section to be in the same order as the interface.
The MMX sort functionality will do that. After you execute the sort, the interface and implementation will be in the same order.
Question 3: I want the body of a generated method to look something like this...
The MMX [add new method] will automatically add a customizable code stub to your method's body. Parameters are supported in the code stub, but I have not seen the list of supported parameters. Here is a sample
procedure TForm1.NewMethod;
begin
// TODO TForm1.NewMethod default body inserted
end;
回答2:
ModelMaker Code Explorer can do it. See http://www.modelmakertools.com/articles/sort-rearrange-code.html#sorting-scheme
来源:https://stackoverflow.com/questions/580983/delphi-ide-how-to-change-the-way-class-completion-works