Hello there

Hello there,

Is there any way to mark an anonymous as deprecated?

For a class type, the syntax is:

type
TDeprecated = class
end deprecated 'use XXX instead';

This won't compile:

type
TFoo = reference to function: Integer; deprecated 'use TBar instead';

Comments

  1. According to the help: "The 'hint' directives platform, deprecated, and library may be appended to any declaration". It's either a compiler bug or a doc bug :-) I notice that there's a number of times in the source where the deprecated directive is commented out for other types of declarations.

    ReplyDelete
  2. Does it compile by removing the semi colon before deprecated?

    ReplyDelete
  3. Actually you're asking about method reference types, not about anonymous methods.

    Anyway: not supported for procedure of object either.

    type
    { [dcc32 Error] ClassConstUsageConsoleProject.dpr(14): E1030 Invalid compiler directive: 'DEPRECATED' }
    TMyProcedure = procedure() of object deprecated 'do not use TMyProcedure';
    { [dcc32 Error] E1030 Invalid compiler directive: 'DEPRECATED' }
    TMyProcedure = reference to procedure() deprecated 'do not use TMyProcedure';

    ReplyDelete
  4. Isn't there a trick whereby you can apply deprecated in an alias declaration?

    https://stackoverflow.com/q/44437900/505088

    ReplyDelete
  5. David Heffernan That trick works in both other cases as well:

    type
    TMyProcedureOld = procedure() of object;
    TMyProcedure = TMyProcedureOld deprecated 'do not use TMyProcedure';
    TMyReferenceOld = reference to procedure();
    TMyReference = TMyReferenceOld deprecated 'do not use TMyReference';

    ReplyDelete
  6. Jeroen Wiert Pluimers That's indeed a nice workaround. However, it won't work when using generic types, which is my case:

    // E2508 Type parameters not allowed on this type
    TFactoryOld = reference to function: T;
    TFactory = TFactoryOld deprecated;

    // works
    TFooOld = reference to function: Integer;
    TFoo = TFooOld deprecated;

    ReplyDelete
  7. Write a custom attribute and apply that attribute to the class. Eg, DeprecatedAttribute = class (TCustomAttribute)
    constructor Create(const DeprecatedMsg: string); end;

    [Deprecated('your message')]
    ClassDeclaration

    ReplyDelete
  8. CHUA Chee Wee How is the compiler warning generated? (which I assume Augustin is after)

    ReplyDelete
  9. Doesn't the compiler emit a warning when you annotate with an non existent attribute? Will check ASAP

    ReplyDelete
  10. David Nottage add deprecated to the constructor or the attribute class to remind you to look at the attribute usage.

    DeprecatedAttribute = class(TCustomAttribute)
    public
    constructor Create(const Msg: string); deprecated 'Please review attached code';
    end;

    [Deprecated('Don''t use this anymore')]
    TObsolete = reference to function: T;

    ReplyDelete

Post a Comment