Displaying Unused Local Variables and Parameters

The Methods menu of the Class Browser or Primitive Types Browser enables you to audit the local variables in the current method, display those that are unused, and remove one unused local variable or all unused local variables in the method.

To audit and maintain local variables in the method displayed in the editor pane

  1. Select the Unused Local Variables command from the Methods menu. (This command is disabled if the method is uncompiled or in error.)

    If there are no unused variables, a message box displays There are no unused local variables.

    If there is one or more unused local variable in the method, the first unused local variable is highlighted in the editor pane and the Find Unused Variables dialog displays the name of the first unused local variable.

  2. To display the next unused variable, click the Find Next button. If there are no more in the current method, the dialog is closed and a message box displays There are no more unused local variables.

  3. To remove the displayed unused variable from the method source, click the Remove button.

    The logic then continues as though you had clicked the Find Next button.

  4. To remove all unused variables from the method source, click the Remove All button.

    The dialog is then closed and a message box lists the names of all variables that have been removed from the method.

  5. To close the Find Unused Variables dialog, click the Cancel button. (No previous remove actions are undone.)

Any changes made to the method can be undone and the method will be unsaved. (Pressing F8 saves and recompiles a changed method.)

The Schema menu in the Schema Browser enables you to audit the local variables that are unused in all methods in a schema or class.

To audit local variables and parameters in all methods or a class of the schema selected in the Schema Browser

  1. Select the Find Unused Local Variables/Parameters command from the Schema menu.

    The Find Unused Local Variables and Parameters dialog, shown in the following image, is then displayed.

  2. If you do not want to search for unused local variables and parameters in all methods in all schemas (the default value), perform one of the following actions in the Search Criteria group box.

    • Select the Search selected schema option button and in the combo box below the option button, select the schema in which you want to locate unused local variables and parameters in all methods.

    • Select the Search selected schema and all sub-schemas option button and in the combo box above the option button, select the schema in which you want to locate unused local variables and parameters in all methods in that schema and its subschemas.

    • Select the Search selected class in selected schema option button and in the combo box below the option button, select the class of the schema selected in the first combo box or that has a local copy class whose methods will be scanned for unused local variables and parameters.

      For details about filtering the entries displayed in the list box associated with the combo box, see "Filtering Entries in Combo Box and List Box Text", in Chapter 2.

  3. In the Reporting Options group box, uncheck the:

    • Local Variables check box if you do not want to display unused local variables. This check box is checked by default; that is, unused local variables are output to the report.

    • Method Parameters check box if you do not want to display unused method parameters. This check box is checked by default; that is, unused method parameters are output to the report.

      If you want to display unused method parameters in all methods in the schema instead of all methods except for event methods (the default), select the All Methods option button. The Parameters group box is visible only when the Method Parameters check box is checked.

  4. In the Output Options group box, select the Print Preview option button if you want to preview the unused local variables and parameters report output.

    By default, the Methods List Browser option button is selected, indicating that the unused local variables and parameters are displayed in a Methods Browser, shown in the following image.

    To display the method source with the unused item visible in the editor pane below the list on the form, click on a method in the list. You can edit this method source.

  5. In the Parameters group box of the reporting options, check the Ignore Inherited Methods check box if you want to exclude the parameters of any method that has reimplementations from the parameters unused list, regardless of whether the parameters are used. This covers the case where the superclass implementation of a method are essentially blank default implementations that are then properly defined in the subclasses.

    If you include the tag [ExcludeFromUnusedParameterReport] (which must be enclosed within [ ] bracket symbols) on the same line as an unused parameter, that parameter is not included in the report. For example, the first of the following code fragment comments does not exclude the unused parameter from the report, but the second example does.

    run(indx: Integer, str: String) updating; // [ExcludeFromUnusedParameterReport]
    run(indx: Integer, // [ExcludeFromUnusedParameterReport]
        str: String) updating; 

    The UnusedParameterReport global constant category contains the "ExcludeFromUnusedParameterReport" global constant, which you can use to locate the string tag in comments by using the local or global search functionality.

  6. Click the Search button to initiate the search. Alternatively, click the Cancel button to abandon your selections.

When a scan is performed using the Find Unused Local Variables/Parameters command from the Schema menu and the located unused variables and parameters are displayed in the Unused Local Variables/Parameters form, double‑clicking a method entry in the list for an unused local variable entry results in all listed unused local variables being removed from the method source and the method is then recompiled. All of the unused local variable entries in the list for that method are removed from the list except for the last entry, so that you can view the method changes. You can also undo the changes, if required. (Multiple undo actions may be required.)

If there is no remaining text between the vars and begin statements, the vars section is removed. No comments are removed.

You can also remove unused local variables by selecting the Remove Unused Local Variables command in the Methods menu.

If you click the only remaining entry for a method again and there are no changes required, the entry is removed from the list.

The result of print preview search output to a print‑ready report contains the: