- Delphi Cookbook
- Daniele Spinetti Daniele Teti
- 189字
- 2025-04-04 16:22:47
There's more...
Attributes are a very powerful mechanism with which to add information in a declarative way. In fact, attributes can extend the normal object-oriented model with aspect-oriented elements (you can find more info here: https://en.wikipedia.org/wiki/Aspect-oriented_programming).
Attributes are useful when building general-purpose frameworks: to figure out what attributes and RTTI are capable of doing, try taking a look at the RESTAdapter of the DMVC framework (https://github.com/danieleteti/delphimvcframework or https://danieleteti.gitbooks.io/delphimvcframework/content/chapterstaterest_adapter_md.html).
In some cases, you might write an incorrect attribute name, or not import the unit containing that attribute; in this case, the compiler generates a warning as following—Unsupported language feature: 'custom attribute'. Watch out! As I wrote, it generates only a warning and the written code will not work as desired (if you have done some consideration on that attribute); if you want to generate an error instead, you have to set the Unsupported language feature to error. Go to Project | Options | Delphi Compiler | Hint and warnings | Unsupported Language Feature and set the value to error. From now on, every Unsupported language feature generates a compiler error.