标签:控件 Default Delphi write read default stored property 属性
转:https://www.cnblogs.com/h2zZhou/p/5909274.html
property ButtonSize: Integer read FButtonSize write SetButtonSize default 0;
property Color: TColor read FColor write SetColor default clBtnHighlight;
property Increment: TScrollBarInc read FIncrement write FIncrement stored IsIncrementStored default 8;
property Margin: Word read FMargin write FMargin default 0;
property ParentColor: Boolean read FParentColor write SetParentColor default True;
property Position: Integer read FPosition write SetPosition default 0;
property Range: Integer read FRange write SetRange stored IsRangeStored default 0;
property Smooth: Boolean read FSmooth write FSmooth default False;
property Size: Integer read FSize write SetSize default 0;
property Style: TScrollBarStyle read FStyle write SetStyle default ssRegular;
property ThumbSize: Integer read FThumbSize write SetThumbSize default 0;
property Tracking: Boolean read FTracking write FTracking default False;
property Visible: Boolean read FVisible write SetVisible default True;
这是类TControlScrollBar中的属性定义,其中的Range属性中存在stored IsRangeStored定义。
先说一下这个命令的语法:stored 后面加一个Boolean类型的变量声明,例如stored False 或 stored true
那么这个stored 是什么意思呢?
总所周知,Delphi中的控件属性实际上是记录在.dfm文件中,编译时编译进入Exe的。这个stored就是确定是否将该属性记录在.dfm文件中,如果不记录是什么意思,其实也就是这个属性是失效的。说白了就是可以通过条件控制这个属性是否可以使用。为什么要这样做呢?
其实原因是这样的:
可以使用这个stored命令来设定互斥属性,什么是互斥属性?也就是一个属性使用的同时就禁止另一个属性的使用。上面的例子中stored IsRangeStored 其中IsRangeStored 是一个函数
function TControlScrollBar.IsRangeStored: Boolean;
begin
Result := not FControl.AutoScroll;
end;
也就是说当AutoScroll为True时Stored为False,也就是不记录,反之亦然,说白了就是有你没我,有我没你。使用这个属性可以防止属性之间的相互干扰。
Default这个命令就很简单,用于设定这个属性的初始值(注意这个Default只能用于设定ordinal, pointer or small set type)。不过这个初始值可以记录在.dfm中的,与在类的Create中赋值是不同的,嘿嘿,不过效果没什么区别。
标签:控件,Default,Delphi,write,read,default,stored,property,属性 来源: https://www.cnblogs.com/CipherLab/p/15853480.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。