If you take a look at sourcecode for the Finish derived attribute declaration from the previous model, you’ll note it looks like this:
property Finish: DateTime read get_Finish;
i.e. it is a read-only property. This kinda makes sense, given what we now know about derived attributes. If the value of my attribute is calculated, the framework by itself cannot figure out how to undo it i.e. how to tear apart the value into the original parts used to calculate it in the first place. This may not even be algorithmically possible.
However, sometimes it is possible, and in these cases, we need a way to tell the framework how to do it. Let’s stick with our Appointment example. The Finish time was derived by taking the Start time and adding the number of minutes held in the Duration attribute. In my case, if someone assigns a new value to the Finish attribute, I’ll change the Duration to reflect the difference between my Start time and this new Finish value.

How? Well, select the Finish attribute in your model, and in the object inspector, set the DerivedSettable property to True. If you now look at the sourcecode for the Finish declaration, a setter method (called set_Finish) has been added. We’ll add our logic to recalculate the Duration in this setter method, but first we need to tell ECO that we are changing the logic in here, and to leave it alone in the future. We do this by removing the [ECOAutoMaintained] attribute from the property declaration in our sourcecode (Don’t worry, there is a comment reminding you to do this in the generated setter method). My new set_Finish method looks like this:
procedure Appointment.set_Finish(Value: DateTime);
begin
// If you add user code here, please remove the [EcoAutoMaintained] attribute
// from the property declaration in the interface section
Duration := Convert.ToInt32(Value.Subtract(Start).TotalMinutes);
end;
The new value for Finish is passed in as the Value parameter. I subtract from this the Start time, and use the the difference in minutes to set the value of the Duration attribute.
What this means is that not only can I set the Start and Duration and it will calculate the Finish, but I can set the Finish and it will calculate a new Duration.
Be the first to leave a comment. Don’t be shy.