对于一个类的每个设置器,我必须实现一些事件逻辑(OnChanging,OnChanged):
procedure TBlock.SetWeightIn(const Value: Double);
var OldValue: Double;
begin
OldValue := FWeightIn;
DoOnChanging(OldValue, Value);
FWeightIn := Value;
DoOnChanged(OldValue, Value);
end;
procedure TBlock.SetWeightOut(const Value: Double);
var OldValue: Double;
begin
OldValue := FWeightOut;
DoOnChanging(OldValue, Value);
FWeightOut := Value;
DoOnChanged(OldValue, Value);
end;
您能否建议一种方法来实现这一点,而无需为每个 setter 复制所有这些行?