Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is possible to mark an entire const block as deprecated?

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.

like image 290
Daniel Santos Avatar asked Dec 04 '14 14:12

Daniel Santos


People also ask

How do you mark a class deprecated?

You need to use the [Obsolete] attribute. Example: [Obsolete("Not used any more", true)] public class MyDeprecatedClass { //... }

Why are we deprecated?

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.


1 Answers

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.

like image 128
Tom Brunberg Avatar answered Sep 29 '22 22:09

Tom Brunberg