• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

编写Delphi控件属性Stored和Default的理解及应用

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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中赋值是不同的,嘿嘿,不过效果没什么区别。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VHDL 编写一个16位乘法器 并用matlab模拟输入输出发布时间:2022-07-18
下一篇:
Matlab曲面拟合和插值发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap