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

    好的代码像粥一样,都是用时间熬出来的
  • 相关阅读:
    hdu 2444 交叉染色判断二分图+二分最大匹配
    uva 交叉染色法10004
    poj 3177&&3352 求边双联通分量,先求桥,然后求分量( 临界表代码)
    poj 3177&&poj 3352加边构双联通(有重边)用tarjan 模板求的
    poj 3006水题打素数表
    POJ 3352 无向图边双连通分量,缩点,无重边
    hdu 1430 魔板 康托展开 + 很好的映射
    D. Artsem and Saunders 数学题
    vijos P1412多人背包 DP的前k优解
    1475 建设国家 DP
  • 原文地址:https://www.cnblogs.com/jijm123/p/14934864.html
Copyright © 2011-2022 走看看