Synchronize Declaration / Implementation - update method signature

16-11-2004

A very common programmers task is to adjust an existing method's signature. For example add or remove a parameter, change a procedure into a function, or change the function's result type. After you changed a method's signature in the implementation (or declaration), the "Synchronize Declaration / Implementation" refactoring updates the corresponding signature in the declaration(or implementation) depending on the editor cursor position.

An example

Suppose you have a class TSample with a method DoSomething like this:

type
TSample = class (TObject)
public
procedure DoSomething;
end;

implementation

procedure TSample.DoSomething;
begin
// actual code here
end;

Suppose now that you want to change this method to a function, returning a Boolean. It also should have a parameter "Level: Integer". After changing the implementation header to the new signature...

type
TSample = class (TObject)
public
procedure DoSomething;
end;

implementation

function TSample.DoSomething(Level: Integer): Boolean;
begin
// actual code here
end;

...rather than manually adjusting the method declaration in the class interface, now press Ctrl+Alt+Y (default keyboard shortcut) to invoke the Synchronize Declaration / Implementation refactoring:

Refactor

type
TSample = class (TObject)
public
// declaration signature updated based on implementation
function DoSomething(Level: Integer): Boolean;Refactor Result
end;

implementation

function TSample.DoSomething(Level: Integer): Boolean;
begin
// actual code here
end;

..that updates the declaration with the changes you made in the implementation.

Similar, if you modify the method signature in the class definition and press Ctrl+Alt+Y in the declaration, the implementation signature - method type, parameter list and result type - are updated.

Note that the keyboard shortcut Ctrl+Alt+Y is a default and can be adjusted to your preferences.