[lazarus] New feature: Complete Code

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Oct 15 09:30:23 EDT 2001


Hi all,

I have committed a new feature for the source editor called "Complete Code".
To use Complete-Code you need only to define a key in the editor options (I use Ctrl+Shift+C).

"Complete Code" can do 2 things:
1. Complete Classes:
  (this is similar to Delphis Auto-Class-Completion)
  Move the cursor into a class definition and press your key for "Complete Code".
  All properties are completed and all missing method bodies are added.

  1. Example:  

    "property MyInteger: integer;"

   will be changed to

    "property MyInteger: integer read fMyInteger write SetMyInteger;"

   and in the private section the following two lines are inserted:

    "var fMyInteger: integer;"
    "procedure SetMyInteger(const AValue: integer);"

   (if there is no private section, it will be inserted)


  2. Example:

    "property MyChar[Index: integer]: char;"

   will be changed to

    "property MyChar[Index: integer]: char read GetMyChar write SetMyChar;"

   and in the private section the following two lines are inserted:

    "function GetMyChar(Index: integer): char;"
    "procedure SetMyInteger(Index: integer; const AValue: integer);"


  3. Small examples:

    3.1 "property Ch: char read ReadCh;"
       will not be changed.  Only the function will be inserted.

    3.2 "property Ch: char read;"
       will be changed to
        "property Ch: char read fCh;"


  Foreach method in the class definition, that has no body, a body will be inserted.
  For example:

     "procedure SetMyInteger(const AValue: integer);"

    will insert a method body to the implementation section:

     "procedure TMyClass.SetMyInteger(const AValue: integer);
      begin

      end;"



2. Complete forward declared procedures:

  Forward procedures are for example procedures in the interface section or procedures with the "forward" specifier. Move the cursor to one of these procedures and the IDE will automatically append the procedure at the end of the program/implementation section with a body.
For example:

function DoSomething; forward;

will produce

function DoSomething;
begin

end;


Comments:
The codetools try to keep your comments untouched, that means, when the codetools search for an insert position it determines with some simple heuristics what comment belongs to what code.
For example, the codetools will try not to split up the following:

  1.  i: integer; // an integer

  2.  c: char; { ...
       ... comment ... }

  3.  // Procedure DoSomething
      //    Params: none
      //    Returns: nothing
      procedure DoSomething;
      begin

      end;



Mattias






More information about the Lazarus mailing list