Difference between revisions of "Cody"

From Free Pascal wiki
Jump to navigationJump to search
Line 69: Line 69:
 
**It also shows if a variable is written by a property.
 
**It also shows if a variable is written by a property.
 
**You can select/unselect by clicking on a member.
 
**You can select/unselect by clicking on a member.
 +
 +
=Remove With block=
 +
 +
This tool removes a '''With''' and inserts the with expression in front of each identifier needing it.
 +
 +
*Requires: cursor on a '''With''' expression (e.g. the variable between the keywords '''With''' and '''Do''')
 +
*Menu item: Source Editor / popup / Refactoring / Remove With block
 +
*Shortcut name: ''Remove With block''  (in the IDE under options Editor / Key mapping)
 +
 +
For example:
 +
 +
<Delphi>
 +
with Button1 do begin
 +
  Name:='Button1';
 +
  Caption:='Ok';
 +
end;
 +
</Delphi>
 +
 +
becomes:
 +
 +
<Delphi>
 +
Button1.Name:='Button1';
 +
Button1.Caption:='Ok';
 +
</Delphi>
  
 
=See also=
 
=See also=

Revision as of 00:19, 8 May 2011

"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.

Cody adds the following items to the IDE:

PPU files of project

  • Menu item: Project / Show ppu files of project
  • Requires: A compiled project
  • Key name: Show used .ppu files ... (in the IDE under options Editor / Key mapping)

This dialog gives some stats about all used ppu/o files of the project. It shows which unit uses what and where it is used.

Cody ppu files.png

You can sort by double clicking on the column header.

  • General
    • Source: the full file name of the unit source file
    • PPU: the full file name of the unit ppu file.
  • Uses: This lists all units used by the unit.
  • Used by: This lists all units that uses the current unit directly.
  • Uses path: This gives one path from the project main source to the unit. This is not necessarily the shortest path.

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:

<Delphi> 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; </Delphi>

  • Requires: cursor in a class
  • Menu item: Source Editor / popup / Source / Add Assign method ...
  • Shortcut name: Add Assign method (in the IDE under options Editor / Key mapping)

Cody add assign method1.png

  • Method name: type in the name of the new method. It is automatically checked if there is already such a method or if an ancestor has inherited one.
  • Parameter name: the parameter name is taken from the inherited method, otherwise Source.
  • Parameter type: the parameter type is taken from the inherited method, otherwise TObject. If this type is different than the current class an if-then-else block is added.
  • If there is an inherited method:
    • Check 'Override' to override it. This appends the override method modifier.
    • Check 'Call inherited' to add a line 'inherited'.
    • Check 'Call inherited only if wrong class' to call the inherited method only in the else part. This is needed for all direct descendants of TPersistent.
  • Select members to assign:
    • This lists all variables and all properties that are assignable (readable and writable).
    • It also shows if a variable is written by a property.
    • You can select/unselect by clicking on a member.

Remove With block

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

  • Requires: cursor on a With expression (e.g. the variable between the keywords With and Do)
  • Menu item: Source Editor / popup / Refactoring / Remove With block
  • Shortcut name: Remove With block (in the IDE under options Editor / Key mapping)

For example:

<Delphi> with Button1 do begin

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

end; </Delphi>

becomes:

<Delphi> Button1.Name:='Button1'; Button1.Caption:='Ok'; </Delphi>

See also