Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I must say its not much clear to me what kind of example do you need. IMHO in <a href="http://docwiki.embarcadero.com/RADStudio/XE4/en/Overview_of_Attributes" rel="noreferrer">http://docwiki.embarcadero.com/RADStudio/XE4/en/Overview_of_Attributes</a> is everything you should need, perhaps providing that you have some basic knowledge of annotation and/or aspect programming resp. </p> <p>An example depends on the way/purpose an author of particular SW used attributes for. You mentioned ORM system: the typical usage here is to annotate member of class representing DB entity with additional information neccessary for DB operation in the backend of such framework. Let assume you have a DB entity having field COMPANY CHAR(32) NOT NULL and you want to represent it in Delphi class:</p> <pre><code>TSomeDBEntity = class(...) FCDS: TClientDataset; ... constructor Create; ... [TCharColumn('COMPANY', 32, false)] property CompanyName: string read GetCompanyName write SetCompanyName; end; </code></pre> <p>then you will define attribute TCharColumn with constructor</p> <pre><code>constructor TCharColumn.Create(const AFieldName:string; ALength:integer; ANullable:boolean); begin inherited; FName := AFieldName; FLength := ALength; FNullable := ANullable; end; </code></pre> <p>And usage of such annotation could look something like this:</p> <pre><code>FCDS := TClientDataset.Create(nil); RttiContext := TRttiContext.Create; try RttiType := RttiContext.GetType(self.ClassType); Props := RttiType.GetProperties; for Prop in Props do begin Attrs := Prop.GetAttributes; case Prop.PropertyType.TypeKind of tkUString: begin for Attr in Attrs do if Attr is TCharColumn then begin ColAttr := TCharColumn(Attr); FCDS.FieldDefs.Add(ColAttr.FName, ftString, ColAttr.FLength, not ColAttr.FNullable); end; end; else //... ; end; end; finally RttiContext.Free; end; </code></pre> <p>This piece of program demonstrates, how to define fields in dataset in run-time based on annotation in Delphi. We are limited little bit due lack of named parameters, hence working with parameter list is not flexible as should be e.g. like in Java (compare TMS Aurelius annotation set <a href="http://www.tmssoftware.com/site/manuals/aurelius_manual.pdf" rel="noreferrer">http://www.tmssoftware.com/site/manuals/aurelius_manual.pdf</a> and <a href="http://www.techferry.com/articles/hibernate-jpa-annotations.html" rel="noreferrer">http://www.techferry.com/articles/hibernate-jpa-annotations.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload