New rule: Restrictive method types should not be used
Prerequisites
- [X] This rule has not already been suggested.
- [X] This should be a new rule, not an improvement to an existing rule.
- [X] This rule would be generally useful, not specific to my code or setup.
Suggested rule title
Restrictive method types should not be used
Rule description
This rule identifies places where procedural types (procedure) and method pointers (procedure of object) are used, and suggests replacing with an anonymous method type (reference to procedure) instead.
Rationale
Anonymous method types are a relatively new addition to Delphi that can contain a reference to
- Non-OO routines
- Instance methods
- Class methods
- Anonymous methods
This makes procedural types (non-OO routines) and method pointers (instance methods and class methods) effectively obsolete.
Makes sense to me.
Something to keep in mind when implementing this rule. If you pass an unassigned event property to an anonymous method, checking if the method is assigned always return true. See embarcadero RSP-43962 for more info (requires log in).