Delphi 2010 introduced custom attributes which can be added to type declarations and methods. For which language elements can a custom attribute be used?
The examples which I have found so far include class declarations, fields and methods. (And AFAIK generic classes do not support custom attributes).
Some examples are shown in this article. It looks like variables (external to any class declaration) also can have attributes.
Based on this article, attributes can be used for
- class and record fields and methods
- method parameters
- properties
- non-local enumeration declarations
- non-local variable declarations
Are there other language elements where attributes can be placed?
Update: this article indicates that custom attributes can be placed before properties: http://francois-piette.blogspot.de/2013/01/using-custom-attribute-for-data.html
It contains this code example:
type
TConfig = class(TComponent)
public
[PersistAs('Config', 'Version', '1.0')]
Version : String;
[PersistAs('Config', 'Description', 'No description')]
Description : String;
FTest : Integer;
// No attribute => not persistent
Count : Integer;
[PersistAs('Config', 'Test', '0')]
property Test : Integer read FTest write FTest;
end;
I guess that there is also a way to read attributes on method arguments like
procedure Request([FormParam] AUsername: string; [FormParam] APassword: string);
type
clause, as well as whatever is declared inside a record or class (member variables, properties, functions, procedures, internal classes, etc.) – Stereotype