Automatically Inserting TODO's

By: Peter Laman

Abstract: This unit adds a command to the IDE that will automatically insert TODO's for each empty block (begin/end, try/finally, and so on with no statements enclosed).

Automatically Inserting TODO's Automatically Inserting TODO's - by Peter Laman

Since Code Insight was included in Delphi, it is easy to automatically create the implementation of methods added to the interface of a class. Simpy type Ctrl+Shift+C and Delphi will create the method body, without any statements (well, if it is an overridden method, it might add the keyword "inherited"). If you are implementing an interface, Ctrl+Space lets you automatically add all methods that must be implemented for the interface.

The danger in this is, that it is very easy to forget to actually write these method bodies and the compile isn't going to warn you for that.

For that reason, I created the uAutoTodo.Pas unit (See Code Central). If you integrate this unit into the IDE of Delphi, you'll get an extra command in the Edit menu, that allows you to automatically add TODO's for all "empty blocks" in the unit currently selected in the source code editor.

For example, support your source code contains the following:


function EmptyFunction: Boolean;
begin
end;

{ TObj }

procedure TObj.EmptyMethod;
begin

end;

procedure TObj.UncompletedMethod(const I: Integer);
begin
  if I > 0 then
    try
    finally
    end;
end;

Then inserting Auto-TODO's will yield the following result:


function EmptyFunction: Boolean;
begin
  //TODO 5 -oPeter -cEmpty Block : EmptyFunction (begin/end in function)
end;

{ TObj }

procedure TObj.EmptyMethod;
begin
  //TODO 5 -oPeter -cEmpty Block : TObj.EmptyMethod (begin/end in procedure)
end;

procedure TObj.UncompletedMethod(const I: Integer);
begin
  if I > 0 then
    try
      //TODO 5 -oPeter -cEmpty Block : TObj.UncompletedMethod (try/finally in procedure)
    finally
      //TODO 5 -oPeter -cEmpty Block : TObj.UncompletedMethod (finally/end in procedure)
    end;
end;

Now it you can use View To-Do list in Delphi, to see if there are any empty blocks left in the unit that need to be implemented. You can download the code for this from Code Central. Instruction for installation are in the file Readme.Txt.


Server Response from: ETNASC04