Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-08

RTTI and Attributes in Delphi 2010

23 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marco van de Voort
to Michael Van Canneyt

In our previous episode, Michael Van Canneyt said:

Show quoted text 7 lines
> Just thought I would let you know... > > http://www.malcolmgroves.com/blog/?p=476 Hm Website not accessible. Can you give us the gist of what is so interesting ?

Has been hinted at several times, so I can make an educated guess:

The project is called exRTTI, and provides RTTI for nearly everything, weak linked to avoid bloating, and directives to indicate a non-weak (strong?) linking, in the case of plugin archs etc.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: Hm Website not accessible. Can you give us the gist of what is so interesting ? Michael.

2009/8/16 Michael Van Canneyt :

Website not accessible. Can you give us the gist of what is so interesting ?

Weird. Anyway, I placed the web page content in a OpenDocument Text format available at:

http://opensoft.homeip.net/~graemeg/rtti_and_attributes.odt

Hope that helps.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Michael Van Canneyt: Hm Website not accessible. Can you give us the gist of what is so interesting ? Michael.

In our previous episode, Michael Van Canneyt said:

Show quoted text 7 lines
> Just thought I would let you know... > > http://www.malcolmgroves.com/blog/?p=476 Hm Website not accessible. Can you give us the gist of what is so interesting ?

I had that too, but later it worked. Now I've also seen the syntax, and I think sb should explain those Delphi devels that in C-like languages function modifiers come BEFORE the declaration, and in Pascal AFTER :-)

Reply by email

Graeme Geldenhuys
to Marco van de Voort

2009/8/16 Marco van de Voort :

I had that too, but later it worked. Now I've also seen the syntax, and I think sb should explain those Delphi devels that in C-like languages function modifiers come BEFORE the declaration, and in Pascal AFTER :-)

Very true! Now lets see what they say on the CodeGear newsgroups. :-)

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: 2009/8/16 Michael Van Canneyt : Weird. Anyway, I placed the web page content in a…
Graeme Geldenhuys wrote 10 lines
2009/8/16 Michael Van Canneyt : > > Website not accessible. Can you give us the gist of what is so interesting ? Weird. Anyway, I placed the web page content in a OpenDocument Text format available at: http://opensoft.homeip.net/~graemeg/rtti_and_attributes.odt Hope that helps.

It does, thank you.

However, it's not so spectacular:
Attributes are simply old .NET stuff they ported to Win32. Seems they had to use a workaround through an attribute class.

I never understood the need for it. RTTI is more than enough for 99.99% of the cases.

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt

In our previous episode, Michael Van Canneyt said:

Show quoted text 9 lines
It does, thank you. However, it's not so spectacular: Attributes are simply old .NET stuff they ported to Win32. Seems they had to use a workaround through an attribute class. I never understood the need for it. RTTI is more than enough for 99.99% of the cases.

Give the customer what he wants. And a customer doesn't know enough to show any restraint. More is always better, and if sb else has it, I also want it.

Reply by email

Paul Ishenin
to Michael Van Canneyt: It does, thank you. However, it's not so spectacular: Attributes are simply old .NET…
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.

Reply by email

Marco van de Voort
to Paul Ishenin

In our previous episode, Paul Ishenin said:

Show quoted text 18 lines
> 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.

I know what .NET uses it for, but that was not the question.

The question is why does this have to be solved using a language construct? Why can't you simply register the Object-Relation mapping somewhere else?

What is the value of making it RTTI? Sure you can abuse RTTI to hang information on any identifier, and make a nice example out of it, but does that really display the requirement for RTTI?

Reply by email

Jonas Maebe
to Marco van de Voort
Marco van de Voort wrote 6 lines
The question is why does this have to be solved using a language construct? Why can't you simply register the Object-Relation mapping somewhere else? What is the value of making it RTTI?

I guess it's grouping information that belongs together. Like with OOP.

Jonas

Reply by email

Michael Van Canneyt
to Paul Ishenin: Imagine you have a db framework which maps delphi classes to database tables. It reads…
Paul Ishenin wrote 18 lines
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.

But that needs to be registered separately anyway, because this varies on the storage back-end. The object-db mapping should never be in the object itself, that is bad design.

Michael.

Reply by email

Graeme Geldenhuys
to Paul Ishenin: Imagine you have a db framework which maps delphi classes to database tables. It reads…

2009/8/16 Paul Ishenin :

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.

tiOPF has metadata classes to do just this, but in both cases they work only well if you have quite simple design. Anything complex (and unfortunately my designs seem to be) those property -> db field mappings simply don't coupe.

I also have tables in by database, where one table contains information for various classes. I have to use tiOPF's hard-coded visitors, so I can manually implement the complex mapping and create/populate the correct classes from a single query.

But yeah, I guess for the general public they could have some uses. I haven't found a use for me though (not yet).

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: But that needs to be registered separately anyway, because this varies on the storage…

2009/8/16 Michael Van Canneyt :

But that needs to be registered separately anyway, because this varies on the storage back-end. The object-db mapping should never be in the object itself, that is bad design.

+1

And what about classes that can be stored in various backends? For example, in tiOPF the same class can be stored in CSV, Tab delimited, XML or any SQL DB - all with a compiler define or parameter to the , foreign keys and primary keys don't mean
anything to XML, CSV etc...

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Paul Ishenin
to Marco van de Voort: In our previous episode, Paul Ishenin said: I know what .NET uses it for, but that was…
Marco van de Voort wrote 5 lines
I know what .NET uses it for, but that was not the question. The question is why does this have to be solved using a language construct? Why can't you simply register the Object-Relation mapping somewhere else?

Because it is a more natural way. I want to give full property declaration in a one place.

What is the value of making it RTTI? Sure you can abuse RTTI to hang information on any identifier, and make a nice example out of it, but does that really display the requirement for RTTI

Currently RTTI is very limited - using it you can only enumerate published members, learn their types and default values (for properties). Attributes completely eliminates limitations.

Best regards,
Paul Ishenin.

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: 2009/8/16 Michael Van Canneyt : +1 And what about classes that can be stored in various…
Graeme Geldenhuys wrote 13 lines
2009/8/16 Michael Van Canneyt : > > But that needs to be registered separately anyway, because this varies on > the storage back-end. The object-db mapping should never be in the object > itself, that is bad design. +1 And what about classes that can be stored in various backends? For example, in tiOPF the same class can be stored in CSV, Tab delimited, XML or any SQL DB - all with a compiler define or parameter to the , foreign keys and primary keys don't mean anything to XML, CSV etc...

That's what I meant with 'this varies on the storage back-end.'... :-)

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt

2009/8/16 Michael Van Canneyt :

That's what I meant with 'this varies on the storage back-end.'... :-)

I was agreeing with you. I simple wanted to explain it a bit clearer to other readers. Many always assume RDBMS are used - which is not always the case.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Paul Ishenin: Because it is a more natural way. I want to give full property declaration in a one place.

2009/8/16 Paul Ishenin :

Currently RTTI is very limited - using it you can only enumerate published members, learn their types and default values (for properties). Attributes completely eliminates limitations.

Explain limitations? Surely you do not want any foreign class to query your private or protected fields? Hence you decide what is viewable by others, making them published. Plus, with the current RTTI you can ever execute published methods etc.. I fail to see what everybody always talk about when they say the RTTI limitations compared to Reflection?

An exact example would be very helpful. And the old "property mapping to database field" doesn't could, because that's a design preference and such mappings are not always appropriate or possible.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

listmember
to Graeme Geldenhuys
Graeme Geldenhuys wrote
An exact example would be very helpful. And the old "property mapping to database field" doesn't could, because that's a design preference and such mappings are not always appropriate or possible.

What I have in mind isn't quite an example but I'd like to voice a need I felt a many times over the years and attributes seem to fulfill it.

Some of these attributes would include 'help', 'copyright' and things like that.

I would use the attributes to display help for any property in the property editor in design time.

I.e. instead of having to read a help file, by pressing a button next to that property I'd see a popup explaining it.

The information provided in these 'help's could also be extracted to generate a help file too.

Same thing for 'copyright', of course, and similar to 'help' it would apply to the class as well as properties and code.

I'd like these to be keywords and similar XML (or like Pascal's 'begin..end') they would also have a closing tag/keyword; so that, for example, 'help_begin' would have 'help_end' as its closing tag/keyword.

Other attributes could be references to external systems such as databases. i.e. field mappings to databases.

While I would like these to be both designtime and runtime, with appropriate compiler swithces we could strip them out of final executable.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: It does, thank you. However, it's not so spectacular: Attributes are simply old .NET…

2009/8/16 Michael Van Canneyt :

However, it's not so spectacular: Attributes are simply old .NET stuff they ported to Win32. Seems they had to use a workaround through an attribute class.

Yes you have to create a descendant of TCustomAttribute when you want to add any attribute to a class. I was curious as to who is responsible for instantiating that class and when does it get freed. It gets instantiated when you query with RTTI and you are responsible for freeing that class.

Here is some more information...
http://wings-of-wind.com/2009/08/17/rad-studio-2010-review-9-%E2%80%93-attributes-the-new-rtti-and-db-access/

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email