我在 Embarcadero C++Builder XE8 中使用以下代码。
在 Unit1.h 中:
private:
void SetValue (Currency value);
Currency FValue;
public:
__property Currency Value = {write= SetValue , read=FValue};
在 Unit1.cpp 中:
void TForm1::SetValue(Currency _Value)
{
FValue= _Value;
Label1->Caption= _Value;
}
在我调用的主程序中:
Value = 10; // it calls SetValue and the Value will be set to 10
Value+= 10; // it does not call SetValue and Value will not be set to 20
为什么不Value+= 10
调用SetValue(20)
?