type
WG = class
private
FActive : Bool;
FState : Integer;
procedure SetActive(State:Bool);
procedure SetState(State:Integer);
public
property Active read FActive write SetActive;
property State read FState write SetState;
end;为什么一定要用property 来访问字段(用万一的话)呢?直接访问字段有什么影响吗?搞不懂,这样写起来好麻烦。
类不仅是重用性好,而且要安全性也好。直接读写字段,安全性很差。你加了
procedure SetActive(State:Bool);
procedure SetState(State:Integer);后就可以对字段的安全进行维护,比如,字段不能为零的时候,你可以在setXXX里面写。
再比如说,万一以后你要对这个字段的值进行一些处理,直接读写的方式就影响了重用性。