Refactoring for enumerated types
Few day ago I faced with the problem. Many enumerated types declared like this:
TMyType = (mtOne, mtTwo, mtThree, mtFour, mtFive);
It was comfortable in older versions of Delphi, when we assigned a value without specifying the type. Ie
LVariable : TMyType;
LVariable := mtThree;
Times have changed now specify the type and prefixes no need anymore.
LVariable := TMyType.mtThree;
How to remove a prefix most painless? Of course, we can create a new kind of type, the old type mark as Deprecated, add a bunch of methods and shoveled a lot of code, because the need to maintain compatibility with legacy code.
There is a solution and it's easier solution suggested by Allen Bauer - use helpers.
TMyType = (One, Two, Three, Four, Five);
TMyTypeHelper = record helper for TMyType
mtOne = TMyType.One deprecated 'Use TMyType.One';
mtTwo = TMyType.Two deprecated 'Use TMyType.Two';
mtThree = TMyType.Three deprecated 'Use TMyType.Three';
mtFour = TMyType.Four deprecated 'Use TMyType.Four';
mtFive = TMyType.Five deprecated 'Use TMyType.Five';
And now works as the old code and the new code. Only for each use of the old prefixes we get a warning
|[dcc32 Warning] Unit41.pas(47): W1000 Symbol 'eThree' is deprecated: 'Use TMyType.Three'|
Please login first in order for you to submit comments
- Page :