-

Refactoring Variables

Refactoring means modifying (improving) the structure of existing source code while preserving its functional behavior.

PLCnext Engineer supports refactoring by providing a mechanism for the automatic and consistent modification of object (variable, FB instance, etc.) properties. Consistent means that the properties to be replaced are considered throughout the solution: in each variables table, Data List, at each code location and within the HMI application. This way, an object can, for example, be renamed with a single step without any functional impact on the code.

For that purpose, the context menu command 'Refactoring' is available, if exactly one object is selected in the following editors:

WARNING
Unintended machine operation
  • Prior to refactoring safety-related variables, make certain that suitable organizational measures (according to applicable sector standards) have been taken to avoid hazardous situations if the application logic functions in an unintended or incorrect way.
  • Verify the impact of refactored variables.

Proceed as follows:

  1. In the editor, right-click the object to be changed and select the 'Refactoring' command from the context menu. In the Cross Function Area, the REFACTORING window is opened.

    The window lists all locations where the respective object is used in your project:

    • declarations,
    • code accesses in standard code,
    • code accesses in safety code,
    • usages in the HMI application.

    Double-clicking a location in the list opens the editor (data list, code worksheet, etc.) with the object highlighted in the editor.

  2. Under the 'New Values' group, enter the desired values in the 'Name', 'Type', or 'Comment' fields or select the values from the drop-down list, if available. (Only the 'Name', 'Type', and 'Comments' values can be entered.)
  3. By default, the checkboxes for all the locations of the object are selected, i.e., the new values will replace all existing values when executing the refactoring command.

    Deactivate the checkbox of each location you want to keep unchanged. Make sure that deselecting does not result in a code error due to inconsistencies.

    Call the context menu command 'Deselect All' or click the corresponding toolbar icon to deselect all of the locations. To select all locations, click the command 'Select All' in the toolbar or in the window's context menu.

  4. Click the icon in the toolbar or select the command 'Refactor All Selected' from the window's context menu to apply the new values at each selected location. The locations in the location list are automatically updated with the new values after refactoring is completed.

    Note
    If the instance name of a function block will be changed, the corresponding instance variable in the associated variables table will be renamed too if there exists exactly one variable with the old name and no variable with the new name.