A fragment of code should be grouped together
Turn the fragment into a method with an explaining name.
| procedure TForm4.Button1Click(Sender: TObject);
|
| for I := 0 to Memo1.Lines.Count - 1 do
|
| Sum := Sum + StrToInt(Memo1.Lines[I]);
|
| Average := Sum / Memo1.Lines.Count;
|
| Edit1.Text := FloatToStr(Average);
|
| function TForm4.CalculateSum: Integer;
|
| for I := 0 to Memo1.Lines.Count - 1 do
|
| Result := Result + StrToInt(Memo1.Lines[I]);
|
| procedure TForm4.Button1Click(Sender: TObject);
|
| Average := Sum / Memo1.Lines.Count;
|
| Edit1.Text := FloatToStr(Average);
|
Extract Method should be used when a method performs more than one complete function. The functions should separated out into distinct methods.
To use Extract Method, highlight the code that should be in its own method and select Extract Method from Castalia's refactoring menu. Castalia will create the new method, replacing the existing code with a call to the new method. Castalia will also decide whether the extracted method should be a procedure or function, and create the code appropriately.
Castalia will then activate the multi-cursor, allowing you to select an appropriate name for the new method.
To finish, press Enter.
See also: Refactoring Overview, Rename Method Refactoring