David Schwartz 426 Posted February 14, 2020 (edited) say you have a class like this: TMyClass = class [attr1( 'abc' )] FField1 : string; . . . [attr2( 'abc' )] property Field1 : string read FField1 write FField1; . . . end; Are attr1 and attr2 basically the same? (And yes, I get that they're different attribute classes. That's not what I'm referring to.) What I mean is, does it make a difference whether you put the attribute on the data field (ie, attr1) or on the property (ie, attr2)? Or are they equivalent? So ... is the property Field1 able to see attr1, or attr2, or both? Edited February 14, 2020 by David Schwartz Share this post Link to post
Attila Kovacs 629 Posted February 14, 2020 (edited) They are different, but you can parse and look for the field or for the property for yourself. You can also put as many attributes to your field/property as you want. Edited February 14, 2020 by Attila Kovacs Share this post Link to post
Lars Fosdal 1792 Posted February 17, 2020 TRttiType.GetProperties.GetAttributes vs TRttiType.GetFields.GetAttributes Personally, I've avoided setting props on fields and only set them on properties. There are parts of the RTL where the opposite applies - f.x. for REST.JsonReflect, which checks the fields and not the properties. Share this post Link to post
David Schwartz 426 Posted February 17, 2020 actually, come to think of it, I guess it's also possible to set attributes on the read and write things, and they can be either fields or methods. I was wondering about the transitivity of the lookup with fields, but with methods it's going to be different. So that pretty much answers it. Share this post Link to post