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

Fpropl : integer; Fprop2 : integer; aVal : integer;

procedure Setprop1(p1 : integer); procedure Setprop2(p2 : integer); public constructor Create(const myVal : integer); property propl : integer read Fpropl write Setpropl; 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.

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment