[fpc-devel] RTTI and Attributes in Delphi 2010

Paul Ishenin webpirat at mail.ru
Sun Aug 16 12:14:45 CEST 2009


Michael Van Canneyt wrote:
> I never understood the need for it. RTTI is more than enough
> for 99.99% of the cases.
Imagine you have a db framework which maps delphi classes to database 
tables. It reads class properties from the rtti and creates db tables 
automatically.

For example:

TStudent = class(TPersistent)
published
  property ID: Integer read FID write FID;
  property Name: String read FName write FName;
  property Age: Integer read FAge write FAge;
  property Group: String read FGroup write FGroup;
end;

How db framework can create a table based on this information? It needs 
some more info about field types, primary keys.

Now using attributes we can extend our class declaration:

TStudent = class(TPersistent)
published
  [TDBField('Integer', 'primary key')]
  property ID: Integer read FID write FID;
  [TDBField('VarChar(100)')]
  property Name: String read FName write FName;
  property Age: Integer read FAge write FAge; // db field type can be 
guessed from the property type here
  [TDBField('VarChar(20)')]
  property Group: String read FGroup write FGroup;
end;

This is just one example. If you remember we thought to use property 
attributes for the LCL previously.

Best regards,
Paul Ishenin.



More information about the fpc-devel mailing list