Sign in Join
Wiki copytemporary

Cody

"Cody" is a Lazarus design time package extending the IDE with some advanced code tools for power users. It is located in the Lazarus sources components/codetools/ide/cody.lpk since Lazarus 0.9.31.

Overview

Cody adds the following items to the IDE:

PPU files of project

This dialog provides statistics about all the current project's used .ppu and .o files.

Note: The codetools will try to parse all used .ppu files. The codetools uses its own ppu parser (not the compiler's parser). The advantage of this is that codetools can read many different versions of ppu. The drawback is that it might not be able to read the very latest version. Cody uses the sources as fallback.

Units

The first page Units shows which unit uses what other units, and where they are used. Note: If a .ppu file cannot be parsed the source (.pas, .pp) will be parsed instead of the .ppu.

You can sort the list by double-clicking on a column header.

Linked Files

The second page Linked Files shows what files, libraries and frameworks are used by the project and what unit links them in.

Insert file at cursor

This opens a file dialog. Select a file, which will be inserted at the current source editor position. If some text was selected, it will be replaced.

Insert call inherited

This adds a call to the inherited method with all parameters. For example:

pascal
type
  TMyClass = class(TComponent)
  public
    constructor Create(AOwner: TComponent); override;
  end;

constructor TMyClass.Create(AOwner: TComponent);
begin
  |
end;

This will add inherited Create(AOwner);:

pascal
constructor TMyClass.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;

If the method is a function and the current line is empty it will prepend a Result:=.

pascal
function TMyClass.ExecuteAction(Action: TBasicAction): Boolean;
begin
  Result:=inherited ExecuteAction(Action);
end;

Add Assign method

If you are using Object Pascal, then you often need to copy an object and so you will probably often write an Assign method. This tool generates the method automatically for you and gives you a dialog to quickly select the members to copy. Here is an example of a produced method code:

pascal
type
  TMyClass = class(TComponent)
  private
    FMyInt: integer;
  public
    procedure Assign(Source: TPersistent); override;
    property MyInt: integer read FMyInt write FMyInt;
  end;

procedure TMyClass.Assign(Source: TPersistent);
var
  aSource: TMyClass;
begin
  if Source is TMyClass then
  begin
    aSource:=TMyClass(Source);
    MyInt:=aSource.MyInt;
  end else
    inherited Assign(Source);
end;

Explode a "With" block

This tool removes a With and inserts the with expression in front of each identifier needing it.

For example:

pascal
with Button1 do begin
  Name:='Button1';
  Caption:='Ok';
end;

becomes:

pascal
Button1.Name:='Button1';
Button1.Caption:='Ok';

Add a "With" block

This tool adds a With around the selection of the Source Editor and removes all occurrences of the expression.

For example:

pascal
Button1.Name:='Button1';
Button1.Caption:='Ok';

becomes:

pascal
with Button1 do begin
  Name:='Button1';
  Caption:='Ok';
end;

Beware: This function does not check for conflicts. For example:

pascal
procedure TForm1.Button1Click(Sender: TObject);
begin
  Button1.Enabled:=Enabled;
end;

When you enclose the assignment the function will stupidly convert to:

pascal
procedure TForm1.Button1Click(Sender: TObject);
begin
  with Button1 do begin
    Enabled:=Enabled; // wrong
  end;
end;

Notes:

Declare Variable

This tool is an interactive version of Variable Declaration Completion. It tries to guess the type and context of the identifier at cursor and gives you a list of possible places to declare the variable.

For example:

pascal
procedure DoSomething;
begin
  i:=3;
end;

Place the cursor on the i and invoke the dialog. Select "local variable" and click Ok. The result is

pascal
procedure DoSomething;
var
  i: Integer;
begin
  i:=3;
end;

You can declare member variables:

pascal
procedure DoSomething(A: TMyClass);
begin
  A.Identifier:='Declare a variable in TMyClass';
end;

You can declare variables on the clipboard. This gives you superior control where the new variable is declared. Move the source editor cursor to the destination and paste (e.g. Ctrl+V). Cody will automatically create a new var section if needed.

Features

Unit / Identifier Dictionary

Cody keeps track of all global identifiers the IDE has ever encountered. This tool lets you browse this IDE history. You can jump to the identifier in the source editor or you can use the identifier. Using means inserting/replacing the identifier at the current source editor position, extending the uses section and extending the project/package dependencies. In other words, this tool is like identifier completion, but with a far-reaching search scope.

Creating a new dockable IDE Window

Cody adds a new form type "IDE Window, dockable", which allows to easily create a new dockable IDE window like the Code Explorer or the FPDoc editor.

It also generates code to register a menu item in the View menu and a shortcut.

Usage:

See also


From the Free Pascal wiki, page "Cody", as it stood on 2020-02-08 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 3, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.