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

    好的代码像粥一样,都是用时间熬出来的
  • 相关阅读:
    Linux 内核 MCA 总线
    Linux 内核PC/104 和 PC/104+
    Linux 内核即插即用规范
    Linux 内核硬件资源
    Linux 内核 回顾: ISA
    Linux 内核硬件抽象
    Linux 内核硬件抽象
    Linux 内核PCI 中断
    Linux 内核存取 I/O 和内存空间
    哥们的面试经历
  • 原文地址:https://www.cnblogs.com/jijm123/p/14934864.html
Copyright © 2011-2022 走看看