Declaring a Custom Attribute Class Creating a custom attribute is the same as declaring a class. The custom attribute class has a constructor, and
properties to set and retrieve its state data. Custom attributes must inherit from TCustomAttribute. The following
code declares a custom attribute with a constructor and two properties:
type
TCustomCodeAttribute = class(TCustomAttribute)
private
Fprop1 : integer;
Fprop2 : integer;
aVal : integer;
procedure Setprop1(p1 : integer);
procedure Setprop2(p2 : integer);
public
constructor Create(const myVal : integer);
property prop1 : integer read Fprop1 write Setprop1;
property prop2 : integer read Fprop2 write Setprop2;
end;
The implementation of the constructor might look like
constructor TCustomCodeAttribute.Create(const myVal : integer);
begin
inherited Create;
aVal := myVal;
end;
Delphi for .NET supports the creation of custom attribute classes, as shown above, and all of the custom attributes
provided by the .NET framework.