Show: Object Pascal C++
Display Preferences

Extract Method Overview (Object Pascal)

From Appmethod Topics
Jump to: navigation, search

Go Up to Refactoring Applications Index

Use the Extract Method refactoring operation to change a code fragment into a method whose name describes the purpose of the method. The Extract Method feature analyzes any highlighted code. If that code is not extractable to a method, the refactoring engine warns you. If the method can be refactored, the refactoring engine creates a new method outside of the current method. The refactoring engine then determines any parameters, generates local variables, determines the return type, and prompts the user for a new name. The refactoring engine inserts a method call to the new method in the location of the old method.

There are certain limitations to the extract method refactoring. They include:

  • Cannot extract expressions, only statements.
  • Cannot extract statements that include a call to inherited in Object Pascal.
  • Cannot extract statements that are contained within a with statement.
  • Cannot extract statements that call a local procedure or function.

If you select an expression and choose the Extract Method command, your selection will be expanded to include the entire statement. If the expression in your statement is used as a result, the extracted code returns a function result in place of the expression.

Note: In Object Pascal, you can apply the Extract Method operation to code with generics.

See Also

Personal tools
In other languages