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:
1 2 3 4 5 6 7 8 9 10 11 12 |
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…
1 2 3 4 5 6 7 8 9 10 11 12 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
type TSample = class (TObject) public // declaration signature updated based on implementation function DoSomething(Level: Integer): Boolean; 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.