I know you can mark a single constant as deprecated using
const
NotDeprConst1 = 1;
DeprConst = 2 deprecated;
NotDeprConst2 = 2;
But, can you mark a whole const block as deprecated without marking the constants one by one?
I would like to do something like:
const deprecated
DeprConst1 = 1;
DeprConst2 = 2;
DeprConst3 = 3;
That doesn't compile however (the compiler sees "deprecated" as a identifier).
Or maybe there's a compiler directive:
{$DEPRECATED ON}
const
DeprConst1 = 1;
DeprConst2 = 2;
DeprConst3 = 3;
{$DEPRECATED OFF}
Embarcadero's hinting directives documentation says you can mark any declaration with a hint (like deprecated) but doesn't elaborate.
You need to use the [Obsolete] attribute. Example: [Obsolete("Not used any more", true)] public class MyDeprecatedClass { //... }
It can be removed in future. To warn the developer about the potential pitfall and to discourage the further usage of gets() , the compiler## emits the warning message. Show activity on this post. deprecated message means, this function is marked as deprecated and may remove from standard in later time.
As you have found out, a const block can not be deprecated in one go. There's also no compiler directive like you were speculating. However, the documentation you refer to says
When a hint directive appears in a unit declaration, it means that the hint applies to everything in the unit. For example, the Windows 3.1 style OleAuto.pas unit on Windows is completely deprecated. Any reference to that unit or any symbol in that unit produces a deprecation message.
By moving deprecated const declarations to a new unit and marking that unit deprecated, you can deprecate a larger amount of declarations in one go. Then, of course, you still need to fix unit references. Whether it saves effort or not is for you to decide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With