Difference between revisions of "Property attributes"

From Free Pascal wiki
Jump to navigationJump to search
m
Line 5: Line 5:
 
([http://docwiki.embarcadero.com/RADStudio/XE6/en/Overview_of_Attributes Attributes reference], [http://delphi.about.com/od/oopindelphi/a/delphi-attributes-understanding-using-attributes-in-delphi.htm tutorial])
 
([http://docwiki.embarcadero.com/RADStudio/XE6/en/Overview_of_Attributes Attributes reference], [http://delphi.about.com/od/oopindelphi/a/delphi-attributes-understanding-using-attributes-in-delphi.htm tutorial])
  
This page describes a proposal for property attributes created in 2007 (thus predating the Delphi syntax).
+
Property attributes are a part of FPC trunk. Please refer to [[Custom_Attributes]] for further information.
 
 
As of 2014, no released version of FPC supports attributes.
 
 
 
According to Sven Barth ([http://free-pascal-general.1045716.n5.nabble.com/Property-attributes-tp5718442p5718444.html Feb 2014]):
 
 
 
<blockquote>
 
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).
 
</blockquote>
 
 
 
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]<br>
 
  PropertySpecifiers ::= [ ... ]
 
                        [ ... ]
 
                        [ATTRIBUTES AttributesArray]<br>
 
  AttributesArray ::= '[' (AttributeDeclaration [, AttributeDeclaration]) ']'<br>
 
  AttributeDeclaration ::= ''''<string>':'<string>''''<br>
 
 
 
== Declaration Examples ==
 
 
 
<syntaxhighlight>
 
TmenuItem = class(...)
 
...
 
property Detachable: Boolean read FDetachable write SetDetachable attributes
 
['widgetsets:qt,gtk,win32', 'implementor:Vasya Pupkin', 'creation-date:01.01.2007'];
 
...
 
end;
 
</syntaxhighlight>
 
 
 
<syntaxhighlight>
 
TxxxDatabase = class(...)
 
...
 
property TransactionModel: TTransactionModel read FtransactionModel write
 
SetTransactionModel attributes ['engines:firebird,oracle,sybase-asa'];
 
...
 
end;
 
</syntaxhighlight>
 
 
 
== How to store additional info ==
 
 
 
There were two suggestions about the place for the property attributes:
 
 
 
#RTTI. Advantage - easier access from application. Disadvantage - bigger final executable.
 
#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.
 
  
 
[[Category:FPC]]
 
[[Category:FPC]]
[[Category:Proposals]]
 

Revision as of 18:35, 20 July 2019

Attributes

Attributes are an Object Pascal syntax feature introduced in Delphi 2010. (Attributes reference, tutorial)

Property attributes are a part of FPC trunk. Please refer to Custom_Attributes for further information.