Some VCL's components have declared Stored, Default or NoDefault attributes for some properties.
eg.
[Stored('IsFontStored')]
property Font: TFont read GetFont write SetFont stored IsFontStored;
or
[Default(False)]
property ParentColor default False;
When we need to declare it?
What tool is using them?
--
pozdrowienia
Krzysztof Szyszka, X-Files Software
Developer of X-DBGrid Component
Embarcadero Technology Partner
http://www.x-files.pl/
Vote for best question.
Score: 6
# Vote: 1
Date Posted: 6-Sep-2012, at 10:03 AM EST
From: Krzysztof Szyszka
Re: [Delphi XE3] Stored, Default, NoDefault attribute for pr
On 9/6/2012 10:03 AM, Krzysztof Szyszka wrote:
> What tool is using them?
As of XE3, the streaming system itself now supports writing from the
associated custom attributes. If you compare System.Classes.pas with the
one from the previous release you can find some of the changes.
Of particular interest would be:
DefaultAttribute = class(TCustomAttribute)
NoDefaultAttribute = class(DefaultAttribute)
StoredAttribute = class(TCustomAttribute)
TWriter.WriteProperties
function IsDefaultPropertyValue
Mark
Vote for best answer.
Score: 3
# Vote: 1
Date Posted: 10-Sep-2012, at 4:02 PM EST
From: Mark Edington
Re: [Delphi XE3] Stored, Default, NoDefault attribute for pr
> Jeff Overcash (TeamB) wrote:
>
> Krzysztof Szyszka wrote:
> >
> > I also noticed that not all properties have attributes and therefore,
> > I ask, when I need to define them in my components?
>
> I expect that we will see more as time goes by. So does not hurt (only a little
> size increase for the RTTI but beyond that no harm in doing both ways)
>
> > Is there a tool in the IDE that uses them?
>
> AFAIK, none. I wouldn't expect anything in the IDE to worry about them until
> all the classes are converted over. Each new release has more converted (I
> started IBX in XE3 for instance).
>
> >
> > BTW.
> > Using the old GetPropInfo from TypInfo unit can automatically obtain
> > much more such information without defining attributes that probably
> > will not allow you to define default values ​​for enumeration types.
>
> Only for published properties, attributes are not restricted to published
> properties.
Of course, but stored specifier is important mainly for published properties.
> enumerated type can be done like this
>
> [Default(Ord(gamOnNewRecord))]
> property ApplyEvent : TIBGeneratorApplyEvent read FApplyEvent write
> FApplyEvent;
Of course. But you may also like this
[Default('gamOnNewRecord')]
property ApplyEvent : TIBGeneratorApplyEvent read FApplyEvent write FApplyEvent;
similar to:
[Stored('IsFontStored')]
property Font: TFont read GetFont write SetFont stored IsFontStored;
> > It would be good to RTTI was able to retrieve this information
> > automatically from TypInfo without having to define attributes.
>
> The old typInfo unit I expect to see very little changes from her on out. I
> expect most new RTTI stuff will be extending System.RTTI.pas. Just IMO though.
IMHO these attributes should be complete, and the rules defining and using clearly
described. Incomplete information is sometimes worse than none.
--
pozdrowienia
Krzysztof Szyszka, X-Files Software
Developer of X-DBGrid Component
Embarcadero Technology Partner
http://www.x-files.pl/
Vote for best answer.
Score: 0
# Vote: 0
Date Posted: 8-Sep-2012, at 12:34 AM EST
From: Krzysztof Szyszka
Re: [Delphi XE3] Stored, Default, NoDefault attribute for pr
Krzysztof Szyszka wrote:
>
> Thanks for the clarification Jeff.
>
> I also noticed that not all properties have attributes and therefore,
> I ask, when I need to define them in my components?
I expect that we will see more as time goes by. So does not hurt (only a little
size increase for the RTTI but beyond that no harm in doing both ways)
> Is there a tool in the IDE that uses them?
AFAIK, none. I wouldn't expect anything in the IDE to worry about them until
all the classes are converted over. Each new release has more converted (I
started IBX in XE3 for instance).
>
> BTW.
> Using the old GetPropInfo from TypInfo unit can automatically obtain
> much more such information without defining attributes that probably
> will not allow you to define default values ​​for enumeration types.
Only for published properties, attributes are not restricted to published
properties.
enumerated type can be done like this
[Default(Ord(gamOnNewRecord))]
property ApplyEvent : TIBGeneratorApplyEvent read FApplyEvent write
FApplyEvent;
> It would be good to RTTI was able to retrieve this information
> automatically from TypInfo without having to define attributes.
>
The old typInfo unit I expect to see very little changes from her on out. I
expect most new RTTI stuff will be extending System.RTTI.pas. Just IMO though.
--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted corridors of Whitehall.
(Fish)
Vote for best answer.
Score: 0
# Vote: 0
Date Posted: 7-Sep-2012, at 1:16 PM EST
From: Jeff Overcash (TeamB)
Re: [Delphi XE3] Stored, Default, NoDefault attribute for pr
> Attributes can be accessed through RTTI. The old style
>
> property Font: TFont read GetFont write SetFont stored IsFontStored;
>
> does not have RTTI. Malcolm Grooves has several examples around this
> (http://www.malcolmgroves.com/blog/?p=476). So using attributes you can do
> things like
>
> uses system.Rtti, Data.DB;
>
> procedure TForm4.Button1Click(Sender: TObject);
> var
> ctx : TRttiContext;
> t : TRttiType;
> p : TRttiProperty;
> a : TCustomAttribute;
> begin
> Memo1.Clear;
> ctx := TRttiContext.Create;
> try
> t := ctx.GetType(TFieldDef);
> for p in t.GetProperties do
> for a in p.GetAttributes do
> if a is DefaultAttribute then
> Memo1.Lines.Add('Property ' + p.Name + ' attribute ' +
> a.ClassName + ' Value ' + String(DefaultAttribute(a).Value))
> else
> if a is StoredAttribute then
> Memo1.Lines.Add('Property ' + p.Name + ' attribute ' +
> a.ClassName + ' Flag ' + BooltoStr(StoredAttribute(a).Flag, true)
> + ' Name ' + StoredAttribute(a).Name);
> finally
> ctx.Free;
> end;
> end;
>
> you will get output like
>
> Property FieldNo attribute StoredAttribute Flag False Name
> Property ChildDefs attribute StoredAttribute Flag True Name HasChildDefs
> Property Precision attribute DefaultAttribute Value 0
> Property Size attribute DefaultAttribute Value 0
>
> I picked TFieldDef cause it has a mix of attributes and non attirbute stuff.
> Notice no output for
>
> property DataType: TFieldType read FDataType write SetDataType default
> ftUnknown;
>
> since even though it has a default it does not also have a corresponding
> Attribute (you do not have to have both, the attribute alone is enough, the
> streaming mechanism works fine with just attributes AFAIK)
>
> Another good example of this from Malcolm for doing validation
> http://www.malcolmgroves.com/blog/?p=530.
>
> http://docwiki.embarcadero.com/RADStudio/XE3/en/Overview_of_Attributes
Thanks for the clarification Jeff.
I also noticed that not all properties have attributes and therefore,
I ask, when I need to define them in my components?
Is there a tool in the IDE that uses them?
BTW.
Using the old GetPropInfo from TypInfo unit can automatically obtain
much more such information without defining attributes that probably
will not allow you to define default values ​​for enumeration types.
It would be good to RTTI was able to retrieve this information
automatically from TypInfo without having to define attributes.
--
pozdrowienia
Krzysztof Szyszka, X-Files Software
Developer of X-DBGrid Component
Embarcadero Technology Partner
http://www.x-files.pl/
Vote for best answer.
Score: 0
# Vote: 0
Date Posted: 7-Sep-2012, at 12:55 PM EST
From: Krzysztof Szyszka
Re: [Delphi XE3] Stored, Default, NoDefault attribute for pr
Krzysztof Szyszka wrote:
>> Some VCL's components have declared Stored, Default or NoDefault attributes for some properties.
>> eg.
>> [Stored('IsFontStored')]
>> property Font: TFont read GetFont write SetFont stored IsFontStored;
>> or
>> [Default(False)]
>> property ParentColor default False;
>>
>> When we need to declare it?
>> What tool is using them?
>
> Does anybody really know why it was introduced? Maybe someone of TeamB?
>
Attributes can be accessed through RTTI. The old style
property Font: TFont read GetFont write SetFont stored IsFontStored;
does not have RTTI. Malcolm Grooves has several examples around this
(http://www.malcolmgroves.com/blog/?p=476). So using attributes you can do
things like
uses system.Rtti, Data.DB;
procedure TForm4.Button1Click(Sender: TObject);
var
ctx : TRttiContext;
t : TRttiType;
p : TRttiProperty;
a : TCustomAttribute;
begin
Memo1.Clear;
ctx := TRttiContext.Create;
try
t := ctx.GetType(TFieldDef);
for p in t.GetProperties do
for a in p.GetAttributes do
if a is DefaultAttribute then
Memo1.Lines.Add('Property ' + p.Name + ' attribute ' +
a.ClassName + ' Value ' + String(DefaultAttribute(a).Value))
else
if a is StoredAttribute then
Memo1.Lines.Add('Property ' + p.Name + ' attribute ' +
a.ClassName + ' Flag ' + BooltoStr(StoredAttribute(a).Flag, true)
+ ' Name ' + StoredAttribute(a).Name);
finally
ctx.Free;
end;
end;
you will get output like
Property FieldNo attribute StoredAttribute Flag False Name
Property ChildDefs attribute StoredAttribute Flag True Name HasChildDefs
Property Precision attribute DefaultAttribute Value 0
Property Size attribute DefaultAttribute Value 0
I picked TFieldDef cause it has a mix of attributes and non attirbute stuff.
Notice no output for
property DataType: TFieldType read FDataType write SetDataType default
ftUnknown;
since even though it has a default it does not also have a corresponding
Attribute (you do not have to have both, the attribute alone is enough, the
streaming mechanism works fine with just attributes AFAIK)
Another good example of this from Malcolm for doing validation
http://www.malcolmgroves.com/blog/?p=530.
http://docwiki.embarcadero.com/RADStudio/XE3/en/Overview_of_Attributes
--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted corridors of Whitehall.
(Fish)
Vote for best answer.
Score: 0
# Vote: 0
Date Posted: 7-Sep-2012, at 10:37 AM EST
From: Jeff Overcash (TeamB)
Re: [Delphi XE3] Stored, Default, NoDefault attribute for pr
> Some VCL's components have declared Stored, Default or NoDefault attributes for some properties.
> eg.
> [Stored('IsFontStored')]
> property Font: TFont read GetFont write SetFont stored IsFontStored;
> or
> [Default(False)]
> property ParentColor default False;
>
> When we need to declare it?
> What tool is using them?
Does anybody really know why it was introduced? Maybe someone of TeamB?
--
pozdrowienia
Krzysztof Szyszka, X-Files Software
Developer of X-DBGrid Component
Embarcadero Technology Partner
http://www.x-files.pl/
Vote for best answer.
Score: 0
# Vote: 0
Date Posted: 7-Sep-2012, at 9:29 AM EST
From: Krzysztof Szyszka
Re: [Delphi XE3] Stored, Default, NoDefault attribute for pr
> > > Some VCL's components have declared Stored, Default or NoDefault attributes for some
> > > properties. eg.
> > > [Stored('IsFontStored')]
> > > property Font: TFont read GetFont write SetFont stored IsFontStored;
> > > or
> > > [Default(False)]
> > > property ParentColor default False;
> > >
> > > When we need to declare it?
> > > What tool is using them?
> >
> > http://docwiki.embarcadero.com/RADStudio/en/Properties
>
> There is not a single word about the attributes!
> Look at [Stored('IsFontStored')] and [Default(False)]
http://docwiki.embarcadero.com/RADStudio/XE3/en/Attributes_Index
I know what are attributes and how can I use these !!!
Write me FOR WHAT are these (Stored, Default, NoDefault) declared in VCL components ?
When I must use these attributes in my components?
WHAT TOOL is using them? What gives?
--
pozdrowienia
Krzysztof Szyszka, X-Files Software
Developer of X-DBGrid Component
Embarcadero Technology Partner
http://www.x-files.pl/
Vote for best answer.
Score: 0
# Vote: 0
Date Posted: 6-Sep-2012, at 11:54 AM EST
From: Krzysztof Szyszka
Re: [Delphi XE3] Stored, Default, NoDefault attribute for pr
Krzysztof Szyszka wrote:
> > > Some VCL's components have declared Stored, Default or NoDefault attributes for some
> > > properties. eg.
> > > [Stored('IsFontStored')]
> > > property Font: TFont read GetFont write SetFont stored IsFontStored;
> > > or
> > > [Default(False)]
> > > property ParentColor default False;
> > >
> > > When we need to declare it?
> > > What tool is using them?
> >
> > http://docwiki.embarcadero.com/RADStudio/en/Properties
>
> There is not a single word about the attributes!
> Look at [Stored('IsFontStored')] and [Default(False)]
http://docwiki.embarcadero.com/RADStudio/XE3/en/Attributes_Index
--
Tom Brunberg
firstname.surname@welho.com
Vote for best answer.
Score: 0
# Vote: 0
Date Posted: 6-Sep-2012, at 11:38 AM EST
From: Tom Brunberg
Re: [Delphi XE3] Stored, Default, NoDefault attribute for pr
> > Some VCL's components have declared Stored, Default or NoDefault attributes for some properties.
> > eg.
> > [Stored('IsFontStored')]
> > property Font: TFont read GetFont write SetFont stored IsFontStored;
> > or
> > [Default(False)]
> > property ParentColor default False;
> >
> > When we need to declare it?
> > What tool is using them?
>
> http://docwiki.embarcadero.com/RADStudio/en/Properties
There is not a single word about the attributes!
Look at [Stored('IsFontStored')] and [Default(False)]
--
pozdrowienia
Krzysztof Szyszka, X-Files Software
Developer of X-DBGrid Component
Embarcadero Technology Partner
http://www.x-files.pl/