zoukankan      html  css  js  c++  java
  • 编写Delphi控件属性Stored和Default的理解及应用

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

  • 相关阅读:
    Qt实现模糊搜索
    Qt解析多级xml文件
    insert into
    Git忽略规则(.gitignore配置)不生效原因和解决
    搭建vue开发环境
    表单
    事件处理
    列表渲染
    条件渲染
    class与style绑定
  • 原文地址:https://www.cnblogs.com/h2zZhou/p/5909274.html
Copyright © 2011-2022 走看看