RAD Studio (Common)
Refactoring Applications

Refactoring is a technique you can use to restructure and modify your code in such a way that the intended behavior of your code stays the same. RAD Studio provides a number of refactoring features that allow you to streamline, simplify, and improve both performance and readability of your application code.

Refactoring is a technique you can use to restructure and modify your existing code in such a way that the intended behavior of your code stays the same. Refactoring allows you to streamline, simplify, and improve both performance and readability of your application code.
Each refactoring operation acts upon one specific type of identifier. By performing a number of successive refactorings, you build up a large transformation of the code structure, and yet, because each refactoring is limited to a single type of object or operation, the margin of error is small. You can always back out of a particular... more 
Renames identifiers and all references to the target identifier. You can rename an identifier if the original declaration identifier is in your project or in a project your project depends on, in the Project Group. You can also rename an identifier if it is an error identifier, for instance, an undeclared identifier or type.
The refactoring engine enforces a few renaming rules:
  • You cannot rename an identifier to a keyword.
  • You cannot rename an identifier to the same identifier name unless its case differs.
  • You cannot rename an identifier from within a dependent project when the project where the original... more 
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... more 
Extracting resource strings helps centralize string definitions which can then be more easily translated, if necessary. You can extract string values to resource strings that are defined in the resourcestring section of your code file. If there is no resourcestring section in your code, the refactoring engine creates one following either the implementation keyword or the uses list.
You cannot create a resource string from the following elements:
  • Constants. For example, const A = 'abcdefg'; cannot be extracted to a resource string.
  • Constants in Parameters. For example, in MyProc(A, B:Integer; C: string='test'); the string cannot be extracted to a resource... more 
You can use the Refactoring feature to create variables and fields. This feature allows you to create and declare variables and fields while coding without planning ahead. This topic includes information about:
  • Declare Variable
  • Initial Type Suggestion
  • Declare Field
Sometimes, you may not want to change code, but want to find references to a particular identifier. The refactoring engine provides Find References, Find Local References, and Find Declaration Symbol commands.
Both Find References and Find Local References commands provide you with a hierarchical list in a separate Find References window, showing you all occurrences of a selected reference. If you choose the Find References command, you are presented with a treeview of all references to your selection in the entire project. If you want to see local references only, meaning those in the active code file, you... more 
Adding or removing a parameter from a function is a commonly performed and tedious programming task. RAD Studio provides the Change Parameters refactoring to automate this task. You can use Change Parameters to add, remove, and rearrange function parameters.
To use this refactoring, select a function name in the Code Editor and choose RefactorChange Params.
When you use the Change Parameters refactoring, the following function signature conflicts can occur:
  • A descendant class contains an override for the function you are refactoring. When you refactor the function, any functions that override the refactored function will also be refactored.
  • A... more 
Sync Edit mode allows you to change all occurrences of an identifier when you change one instance of that identifier. When you enter Sync Edit mode, you can tab to each highlighted identifier in your current Code Editor window. If you change an identifier that appears elsewhere in the file, all occurrences transform to whatever you type, character by character. 
The refactoring engine takes advantage of a versioning mechanism, known as local striping, to allow you to undo renames in source code files. The IDE records the current timestamp of each file included in the current refactoring changeset. The timestamp corresponds to a specific local revision of the file. When you select the undo command, the IDE copies the local backup file that matches that timestamp back over the refactored file.
The important point to understand is that any changes that you make to the files after the refactoring will also be rolled back when you perform an Undo.... more 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!