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';
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';
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.
ReplyDeleteDoes it compile by removing the semi colon before deprecated?
ReplyDeleteDavid Heffernan nope
ReplyDeleteActually you're asking about method reference types, not about anonymous methods.
ReplyDeleteAnyway: 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';
Isn't there a trick whereby you can apply deprecated in an alias declaration?
ReplyDeletehttps://stackoverflow.com/q/44437900/505088
David Heffernan That trick works in both other cases as well:
ReplyDeletetype
TMyProcedureOld = procedure() of object;
TMyProcedure = TMyProcedureOld deprecated 'do not use TMyProcedure';
TMyReferenceOld = reference to procedure();
TMyReference = TMyReferenceOld deprecated 'do not use TMyReference';
Jeroen Wiert Pluimers That's indeed a nice workaround. However, it won't work when using generic types, which is my case:
ReplyDelete// 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;
Write a custom attribute and apply that attribute to the class. Eg, DeprecatedAttribute = class (TCustomAttribute)
ReplyDeleteconstructor Create(const DeprecatedMsg: string); end;
[Deprecated('your message')]
ClassDeclaration
CHUA Chee Wee How is the compiler warning generated? (which I assume Augustin is after)
ReplyDeleteDoesn't the compiler emit a warning when you annotate with an non existent attribute? Will check ASAP
ReplyDeleteDavid Nottage add deprecated to the constructor or the attribute class to remind you to look at the attribute usage.
ReplyDeleteDeprecatedAttribute = 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;