Programming with Castalia : Refactoring : Add Parameter
Previous  Top  Next

A function or method needs more information from its caller

Add a parameter to the function or method's parameter list.
 
function CalculateAge(Birthday: TDateTime): Integer;  
var  
  I: Integer;  
begin  
  I := Trunc(Now - Birthday);  
  if I < 18 then  
    raise EUnderageCustomer.CreateFmt('Customer is only %d', [I]);  
  Result := I;  
end;  
 
downarrow  
function CalculateAge(Birthday: TDateTime; CalculateDay: TDateTime): Integer;  
var  
  I: Integer;  
begin  
  I := Trunc(Now - Birthday);  
  if I < 18 then  
    raise EUnderageCustomer.CreateFmt('Customer is only %d', [I]);  
  Result := I;  
end;  
 
To add a parameter to a function or method, place the cursor in the method and invoke the Add Parameter refactoring. The Add Parameter window will appear:

addparameter

Enter the necessary information about the new parameter:

Name: The parameter name must be a valid identifier.

Type: The parameter type must be a valid type.

Use Default Value: If you would like the parameter to have a default value, check this box and enter the desired default value.

Default Value in Declaration: When checked, the default value is placed in the declaration of the function or method. As of Castalia 3.0, this is not optional. A future update may allow the default value to be placed in the caller.

Click OK, review the suggested changes, and click Apply to apply the changes to the code.

See also: Refactoring Overview