MZ-Tools 3.0 offered a Sort Procedures feature that showed a window with all the procedures of the active code file with Up/Down buttons to sort them manually:
While that feature was very popular, the approach was very time-consuming, because you had to sort manually each file, and when you added new procedures, you had to sort them again manually. Furthermore, there was no way to detect if the procedures of a file were correctly sorted or not. Update (Sep 1, 2016): MZ-Tools 8.0 build 184.108.40.206 reintroduces manual sorting of methods, coexisting with the new automatic sorting of methods explained below.
MZ-Tools 8.0 introduces a new approach, that requires some initial configuration but that pays off many times later. First of all, the term “Procedure” has been changed by “Code Element”. While at the time of this writing you can only sort “procedures” (subroutines, functions and properties), in some future build you will be able to sort also the code elements of the (General)-(Declarations) section (enums, user-defined types, class fields, class constants, events, etc.).
The feature is then renamed to “Sort Code Elements” and shows no window, it sorts instantly the code elements of the active code file using a predefined sorting criteria that you define in the “Options” window, “Team Options” tab, “Code Elements Order” section:
In that window, first you select the parent code element kind, which can be a class, a module or an interface, allowing you to define a different sorting criteria for each one. Once selected a parent, such a class, you then add children code elements, that can be moved up/down to define its priority. In the example above, the order is:
- Class_Initialize method
- Class_Terminate method
- Methods that are event handlers
- Methods that are subroutines
- Methods that are functions
- Everything else (ex: Properties)
The Child Code Element editor provides several options to define a child code element.
- Property (ex: Name matching regular expression).
- Access (any, Public, Private, etc.).
- Context: a “context” is a characteristic of the code element, which can vary depending on the kind of code element.
For example, for methods the available contexts are “Function”, “Sub”, “Event handler” and “Not event handler”:
Once configured the desired sorting criteria, not only you can now sort the code elements of any file with one click, but also you have a Code Elements Order Review as part of the Quality Review feature:
To summarize, the Sort Code Elements feature can provide more productivity using its one-click approach, and also more quality detecting if your code files have their code elements correctly sorted.