Property attributes

From Lazarus wiki
Revision as of 13:27, 22 October 2014 by Tangentstorm (talk | contribs) (added disclaimer about current status of attribute syntax)
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Attributes

Attributes are an object pascal syntax feature introduced in Delphi 2010. (Attributes reference, tutorial)

This page describes a proposal for property attributes created in 2007 (thus predating the Delphi syntax).

As of 2014, no released version of FPC supports attributes.

According to Sven Barth (Feb 2014):

There is a branch which already supports class attributes. Property attributes (or any other kind of attributes) are not supported yet. Also they are implemented Delphi compatible (with attributes being in front of the class instead of after it).

The rest of this page describes the older, proposed syntax, and not any current or planned implementation.


Syntax Diagram

 PropertyDeclaration ::= PROPERTY Identifier [PropertyInterface] [PropertySpecifiers]   [Directives]
PropertySpecifiers ::= [ ... ] [ ... ] [ATTRIBUTES AttributesArray]
AttributesArray ::= '[' (AttributeDeclaration [, AttributeDeclaration]) ']'
AttributeDeclaration ::= '<string>':'<string>'

Declaration Examples

TmenuItem = class(...)
...
property Detachable: Boolean read FDetachable write SetDetachable attributes
 ['widgetsets:qt,gtk,win32', 'implementor:Vasya Pupkin', 'creation-date:01.01.2007'];
...
end;
TxxxDatabase = class(...)
...
property TransactionModel: TTransactionModel read FtransactionModel write
 SetTransactionModel attributes ['engines:firebird,oracle,sybase-asa'];
...
end;

How to store additional info

There were two suggestions about the place for the property attributes:

  1. RTTI. Advantage - easier access from application. Disadvantage - bigger final executable.
  2. PPU. Advantage - info will not be added to executable. Disadvantage - more complicated way of accessing data.

As a result of the discussion PPU storage has been selected. This happened somewhere in 2008 looking at this article's revision history.